【发布时间】:2013-02-06 14:09:14
【问题描述】:
我在 ASP.Net MVC3 中工作。我需要在@Html.DropDownlist 中绑定我的模型值。我已经用项目列表填充了我的模型。
如何将我的模型与 MVC DropDownList 绑定?
【问题讨论】:
-
请发布一些代码以及显示您尝试过的内容
标签: html asp.net-mvc-3 html.dropdownlistfor
我在 ASP.Net MVC3 中工作。我需要在@Html.DropDownlist 中绑定我的模型值。我已经用项目列表填充了我的模型。
如何将我的模型与 MVC DropDownList 绑定?
【问题讨论】:
标签: html asp.net-mvc-3 html.dropdownlistfor
你可以这样做:
@Html.DropDownListFor(model => model.MyValue
new SelectList(Model.MyList, "ValuePropertyName", "TextPropertyName"))
基本上,你需要查找SelectList以及如何使用它。
【讨论】:
你应该这样做:
@Html.DropDownListFor(
x => x.YourItem,
new SelectList(Model.YourItem, "Value", "Text")
)
在执行此操作之前,您需要将模型传递给您的视图return View(model);
希望对你有帮助
【讨论】: