1

我在ASP.Net MVC3工作。我需要将我的模型值绑定在@Html.DropDownlist. 我已经用项目列表填充了我的模型。

如何将我的模型与 MVC 绑定DropDownList

4

2 回答 2

1

你可以这样做:

@Html.DropDownListFor(model => model.MyValue
   new SelectList(Model.MyList, "ValuePropertyName", "TextPropertyName"))

基本上,您需要查找 SelectList 以及如何使用它。

于 2013-02-06T05:59:26.633 回答
1

你应该这样做:

@Html.DropDownListFor(
    x => x.YourItem, 
    new SelectList(Model.YourItem, "Value", "Text")
)

在这样做之前,您需要将模型传递给您的视图return View(model);

希望能帮助到你

于 2013-02-06T05:59:45.857 回答