Search code examples
asp.net-mvcasp.net-mvc-4drop-down-menumarkup

ASP.NET MVC4 Drop Down List in Create View For Model


I am trying to create a drop down list within my create view. For example, I want the drop down selection "AM" to map to the value "0" for the "Wednesday" property within my model. So far, I have this code:

<div class="editor-label">
        <%: Html.LabelFor(model => model.Wednesday) %>
        <%: Html.DropDownListFor(model => model.Wednesday, new SelectList(new List<SelectListItem>(){new SelectListItem{Text = "AM", Value = "0"}}))%>
    </div>

When testing this in the browser, the only item in the drop down list has the text "System.Web.Mvc.SelectListItem." Instead, I want it to display the user-friendly text "AM."

What am I doing wrong?


Solution

  • This worked for me:

    @Html.DropDownListFor(model => model.CompanyName, new List<SelectListItem>{new SelectListItem{Text = "AM", Value = "0"}})