Tuesday, March 20, 2012

make a SelectList object from another C# object to populate a @Html.DropDownListFor Razor control

I stole the following from here.

@model IEnumerable<Sample.Models.Product>
@{
   List<Sample.Models.Category> list = ViewBag.Categories;
   var items = new SelectList(list, "CategoryID", "CategoryName");
}
@Html.DropDownListFor(???, @items)

No comments:

Post a Comment