Reference: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/examining-the-edit-methods-and-edit-view
Content:
1. Familiar with the MVC routing process. If the URL is directed to the corresponding Controller method
2. added the SearchIndex page for simple query.
Http: // localhost: 9898/Movies ,:
The HTML code corresponding to this path is: @ Html. ActionLink ("Edit", "Edit", new {id = item. ID })
Parameter description: The first parameter is linkText, the second parameter is the action method to be called, and the third parameter is the route data generated by an anonymous object:
Http: // localhost: 9898/movies/Edit/1 url path. asp.net will configure (App_Start \ RouteConfig. cs) Follow{controller}/{action}/{id}
Format:{
movies}/{
Edit}/{
1}
Default route Configuration:
{Controller =, action =, id =View Code
If we update URL: http: // localhost: 9898/Movies/Edit? ID = 1 This URL can also be directed to the Edit page just now according to the ActionResult Method
Then, view the Edit Method in the Controller:
ActionResult Edit (id = (movie = RedirectToAction (View Code
We noticed that the method has [] on it. This HttpPost indicates that only the Post request of the page will call this method. If [] is not added before the method, the default value [] indicates that the method is called during the Get request.
Here, make upGetAndPostMethod:
The. cshtml page corresponding to the ActionRestlt Method@model MvcMovie.Models.Movie
Specifies that the Model in the view template is Movie. Let's take a look at the Helper methods in several views:
Html.LabelFor
Helper displays the field name ("Title", "ReleaseDate", "Genre", or "Price ").
Html.EditorFor
Helper loads HTML <input> Elements
Html.ValidationMessageFor
Helper displays the verification information for its corresponding properties
ProcessingPOSTRequest:
= RedirectToAction(
ASP. net mvc model binder receives form data submitted on the page and creates a Movie object as the parameter of ActionResult Edit (Movie movie.
ModelState. IsValidMethod to check whether the submitted data can be edited or updated. If the data is valid, the movies data is saved to the instance of MovieDBContext (db ). MovieDBContextMedium
SaveChangesMethod To save the data to the database. Save and redirect the page to the index page
If the stored data is invalid and does not comply with the rules,Html.ValidationMessageFor
Error Message
<Script src => </script> <script> =. optional (element) |! </Script> <script> val = $ .. optional (element) |> = param [] & val <= param [</script>View Code
Add in webconfig:
/> <! -- Elements removed clarity --> </system. web>View Code
All HttpGet methods are similar. They Get a Movie object and pass it to the View. Get: The data on the page should not be changed.
ActionResult SearchIndex( MovieGenre, GenreLst = List<> GenreQry = d = SelectList(GenreLst); movies = m (!= movies.Where(s => ( View(movies.Where(x => x.Genre ==
3. Add the following code to the SearchIndex. cshtml page:
@Html.ActionLink(, , <p>, <input type= value= /> </p>
4. query page implementation: