
All the methods that create, edit, delete, or otherwise modify data do so in the overload of the method.
#VIEW FROM THE 6 COVER MOVIE#
The Create method passes an empty movie object to the Create view. They get a movie object (or list of objects, in the case of Index), and pass the object (model) to the view. The Validation Tag Helper in the Views/Movies/Edit.cshtml view template takes care of displaying appropriate error messages.Īll the HttpGet methods in the movie controller follow a similar pattern. Later in the tutorial we examine Model Validation in more detail. If JavaScript is disabled, you won't have client-side validation but the server will detect the posted values that are not valid, and the form values will be redisplayed with error messages. If there are any validation errors, an error message is displayed and the form isn't posted.
#VIEW FROM THE 6 COVER CODE#
After saving the data, the code redirects the user to the Index action method of the MoviesController class, which displays the movie collection, including the changes just made.īefore the form is posted to the server, client-side validation checks any validation rules on the fields. The updated (edited) movie data is saved to the database by calling the SaveChangesAsync method of database context. The ModelState.IsValid property verifies that the data submitted in the form can be used to modify (edit or update) a Movie object. The model binding system takes the posted form values and creates a Movie object that's passed as the movie parameter.
#VIEW FROM THE 6 COVER GENERATOR#
The attribute validates the hidden XSRF token generated by the anti-forgery token generator in the Form Tag Helper Public async Task Edit(int id, Movie movie) To protect from overposting attacks, enable the specific properties you want to bind to. The following listing shows the version of the Edit action method. The last line before the closing element shows the hidden XSRF token generated by the Form Tag Helper. The form data will be posted to the server when the Save button is clicked. The elements are in an HTML element whose action attribute is set to post to the /Movies/Edit/id URL. The generated HTML for the element is shown below. In the browser, view the source for the page.

Run the application and navigate to the /Movies URL. The Validation Tag Helper displays any validation messages associated with that property. The Input Tag Helper renders an HTML element. The Label Tag Helper displays the name of the field ("Title", "ReleaseDate", "Genre", or "Price"). The scaffolded code uses several Tag Helper methods to streamline the HTML markup.


specifies that the view expects the model for the view template to be of type Movie. Notice how the view template has a statement at the top of the file. Open the Models/Movie.cs file and add the highlighted lines shown below: using System We have a good start to the movie app, but the presentation isn't ideal, for example, ReleaseDate should be two words.
