【问题标题】:DropDownListFor in MVC3 Aspx EngineMVC3 Aspx 引擎中的 DropDownListFor
【发布时间】:2012-08-14 13:59:46
【问题描述】:

我正在使用 aspx 视图引擎。我使用 SelectList 和 Html.DropDownList 完成了它,但填充应该来自模型,而不是控制器,并且我需要获取所选项目的值,所以我需要 DropDownListFor。我已经看到了答案,但我无法从那里得到使用了什么样的参数。

型号:

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”的所有值,但运行前后没有错误

【问题讨论】:

    标签: asp.net-mvc-3 selectlist viewdata html.dropdownlistfor selectlistitem


    【解决方案1】:

    我想你的意思是说ViewData["Desserts"] = food;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多