Lamda Binding (Html.DropDownListFor)
// The POCO for the Form is stored here, see the <aside> @model montegodata.ModelsView.WorkFlowTestViewModel // Post the Form to the [ Category ] Controller using the [ SelectForm ] HtmlHelper @using (Html.BeginForm("SelectForm", "Category", FormMethod.Post)) // POCO Field Column From The Model @Html.TextBoxFor(m => m.Developer) // Sample Usage @Html.DropDownListFor(m => m.categorySI, new SelectList(Model.categories, "CategoryID", "CategoryName"))
Below is an alternative method using SelectListItem
from System.Web.Mvc DropDownListFor has good cohesion with SelectListItem.
using System.Web.Mvc; public List< /*System.Web.Mvc.*/SelectListItem > categories; SubmissionModelView.categories = new List</*System.Web.Mvc.*/SelectListItem>(); SubmissionModelView.categories.Add(new SelectListItem {Text="Beverages", Value="1"}); @Html.DropDownListFor(m => m.categorySI, Model.categories)