Using Html.DropDownListFor() in ASP.NET MVC
In ASP.NET MVC, it is very easy to create a simple drop-down list with static options.
Write a simple Html.DropDownListFor():
Example:
Consider the following example data:
1 2 3 4 5 6 7 8 9 10 |
|
In your model, create a property that represents the selected item:
1 2 3 4 |
|
In your view, create a dropdown using the following code:
1 |
|
This will generate a dropdown list with "Red" and "Blue" options, and the selected value will be stored in the model's MyColorId property.
The above is the detailed content of How to Create a Simple Drop-Down List Using Html.DropDownListFor() in ASP.NET MVC?. For more information, please follow other related articles on the PHP Chinese website!