Binding an string array to a DropDownList in MVC Razor
Create a SelectList
with your array and pass it to your view:
SelectList list = new SelectList(AgeRagne);
ViewBag.myList = list;
Then in your view, use Html.DropDownlist
:
@Html.DropDownList("myList", ViewBag.myList as SelectList)
That's all
a not very nice but quick way would be to do this :):
<select name="dowList" id="dowList">
@{string[] AgeRagne = new string[] { "Sun", "Mon", "Tues", "Wed" };}
@foreach (var dow in AgeRagne)
{
<option value="@dow">@dow</option>
}
</select>
tho an htmlhelper would be the best long term stable solution.