0
我正在使用aspx视图引擎。我用SelectList和Html.DropDownList做了它,但是填充应该来自模型,而不是控制器,而且我需要获取所选项目的值,所以我需要DropDownListFor。我已经看到答案,但我无法从那里得到什么样的参数被使用。MVC3中的DropDownListFor Aspx引擎
型号:
public List<SelectListItem> food = new List<SelectListItem>();
控制器:
food.Add(new SelectListItem() { Text = "Banana Cake", Value = "BC" });
food.Add(new SelectListItem() { Text = "Apple Waffle", Value = "WF" });
ViewData[" Desserts "] = new SelectList(foodsample.Food);
查看:
<%= Html.DropDownListFor(x => x.food, ViewData["Desserts"] as SelectList)%>
前和运行后,虽然DropDownList中显示所有值与该文本“没有错误的System.Web .Mvc.SelectListItem'