EF5 (7) background using SelectListItem value to display the Select drop-down box in the foreground, MVC background action receive the browser value of 4 ways; Four ways to pass data to the background action Forward View view

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.