Reputation: 523
I'm new in ASP.NET MVC 4, and I'd like to write a simple DropDownListFor(or DropDownList) which gives static value. Example : I'd like to provide choices between 1, 2, 3 and 4
and I want to get value from Select Choices Example :
if i select 1 --> int value = 1,
if i select 2 --> int value = 2
Thank You!
Upvotes: 1
Views: 466
Reputation: 9155
Here is an example, this will create a <Select>
tag with the name attribute of "value" and with the options 1, 2, 3, and 4.
@{
int[] choices = new int[] { 1, 2, 3, 4 };
}
@Html.DropDownList("value", new SelectList(choices.AsEnumerable()))
Upvotes: 1