【发布时间】:2014-09-16 12:11:01
【问题描述】:
我正在尝试将剑道下拉列表与模型绑定,但我在每个选项中都未定义。
型号:
public SelectList CountriesTemp { get; set; }
public int Country{get;set;}
控制器:
public ActionResult Registration()
{
RegistrationModel Model = new RegistrationModel();
Model.CountriesTemp = new SelectList(ObjService.GetCountries(), "CountryID", "Country_Name");
return View(Model);
}
查看页面
@(Html.Kendo().DropDownListFor(m => m.Country)
//The name of the dropdownlist is mandatory. It specifies the "id" attribute of the widget.
.DataTextField("Country_Name") //Specifies which property of the Product to be used by the dropdownlist as a text.
.DataValueField("CountryID") //Specifies which property of the Product to be used by the dropdownlist as a value.
.BindTo(Model.CountriesTemp ) //Pass the list of Products to the dropdownlist.
)
有人可以指导我哪里错了,因为如果我绑定一个简单的 MVC 下拉列表,它工作得很好。只需在 ViewPage 中更改如下所示的一行即可。
@Html.Dropdownlist("CountriesTemp")
【问题讨论】:
-
代替
Model.CountriesTemp = new SelectList(ObjService.GetCountries(), "CountryID", "Country_Name")试试Model.CountriesTemp = new ObjService.GetCountries();。我不认为Kendo.DropDownListFor()使用SelectList -
如果可以的话,它可能需要
.DataTextField("Name")和.DataValueField("Value"),因为它们是SelectList的唯一(相关)属性
标签: asp.net-mvc-3 asp.net-mvc-4 kendo-ui kendo-asp.net-mvc