I\'m using @html.EditorFor
to render my model in edit mode, and a dropdownlist is not rendered.
Here\'s my ViewModel:
public class
binding dropdown list is easy. code as follows
public ActionResult BindWithModel()
{
List items = new List();
items.Add(new SelectListItem
{ Text = "Select Category", Value = "0",
Selected = true });
items.Add(new SelectListItem
{ Text = "Beverages", Value = "1" });
items.Add(new SelectListItem
{ Text = "Condiments", Value = "2" });
items.Add(new SelectListItem
{ Text = "Confections", Value = "3" });
items.Add(new SelectListItem
{ Text = "Dairy Products", Value = "4" });
items.Add(new SelectListItem
{ Text = "Grains/Cereals", Value = "5" });
items.Add(new SelectListItem
{ Text = "Meat/Poultry", Value = "6" });
items.Add(new SelectListItem
{ Text = "Produce", Value = "7" });
items.Add(new SelectListItem
{ Text = "Seafood", Value = "8" });
var model = new CategoryModel()
{
lstCategory = items,
selected = 1
};
return View(model);
}
@model BindMvcDropdownList.Models.CategoryModel
Bind MVC DropDownList with Model
@Html.DropDownListFor(x => x.selected, Model.lstCategory)
code taken from here http://dotnetmentors.com/mvc/how-to-bind-dropdownlist-in-asp-net-mvc-application.aspx