One: Backstage use SelectListItem value to display the Select drop-down box in the foreground
We first look at the database order table, there are 3 orders, their user ID corresponds to the UserInfo user table data, now we have to do is to add an order controller, display the list of orders, and in the modification of the order, the user's ID with a Select drop-down box display, and can submit modified data
1.1 After we have passed the data to the foreground by comparing the original method, the foreground uses a loop to display the select and shows which element is selected
In the cshtml of the foreground, we use the @model command to specify the current model type as the order strong type, which is the advantage of the convenience of the VS editor to directly point out the properties
The last HTML is displayed as
This method is more old-fashioned, we combine selectlistitem value to the foreground display Select drop-down box
1.2 SelectListItem send value to foreground display Select drop-down box
So it's done.
Two: The MVC background action receives the browser to pass the value the 4 kinds of ways;
Now, let's implement the modification, by reviewing the MVC background action to receive the value of the browser 4 ways;
1: Using the data binding mechanism, when the data passed by the current station is the same type as the background, MVC will automatically match the same name and assign a value. For example, the foreground has an ID passed to the background, just the order class has an id attribute, then it will be assigned to the background, this process contains a reflection
2: The original request.form or the Request.QueryString
3: If the passed parameter is a formcollection form collection, it is used directly with the form["key") to obtain
4: According to the routing rules inside the route table, matching here is exactly the ID is the placeholder ID in the route, then it will be assigned
Three: Four ways to pass data in the background action Forward View view
1th, pass the value of ViewBag to the foreground view view
2nd, pass the value of Viewdate to the foreground view view
3rd, pass the value of Tempdate to the foreground view view
4th, pass the model to the foreground view by return view (here is a value)