我正在尝试使用模型绑定一个kendo下拉列表,但我在每个选项中都未定义。
型号:
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")
答案 0 :(得分:0)
看起来你已经发生了冲突(在这里可以发言)。尝试这样的事情:
@(Html.Kendo().DropDownListFor(m => m.Country)
.DataTextField("Text")
.DataValueField("Value") // These may be optional now
.BindTo(Model.CountriesTemp))
或者,您无法使用SelectList
并在模型上执行IEnumerable<Country> Countries { get; set; }
之类的属性。然后绑定看起来像:
@(Html.Kendo().DropDownListFor(m => m.Country)
.DataTextField("Country_Name")
.DataValueField("CountryID")
.BindTo(Model.Countries))