我尝试从Jquery中的控制器操作中读取Kendo Dropdownlist。代码是
$("#CountryName").kendoDropDownList({
dataTextField: "Description",
dataValueField: "Id",
dataSource: {
transport: {
read: {
dataType: "jsonp",
url: "Shared/CountryAjax"
}
}
}
});
[HttpPost]
public ActionResult CountryAjax(string countryId)
{
var countries = this._decodeBL.GetAllCountriesList();
return new JsonResult
{
Data = new SelectList(countries, "Id", "Description", "Canada")
};
}
但它永远不会执行CountryAjax。我需要帮助。感谢。
答案 0 :(得分:0)
我发现你的代码中有两个错误。首先,您应该在服务器方法中使用[HttpGet]注释。其次,您不应该在服务器方法中接收countryId。
请参阅下面的固定代码。
$("#CountryName").kendoDropDownList({
dataTextField: "Description",
dataValueField: "Id",
dataSource: {
transport: {
read: {
dataType: "jsonp",
url: "Shared/CountryAjax"
}
}
}
});
[HttpGet]
public ActionResult CountryAjax()
{
var countries = this._decodeBL.GetAllCountriesList();
return new JsonResult
{
Data = new SelectList(countries, "Id", "Description", "Canada")
};
}
答案 1 :(得分:0)
$("#selectYears").kendoDropDownList({
dataTextField: "Text",
dataValueField: "Value",
//dataSource: data2,
dataSource: {
transport: {
read: {
type: "GET",
dataType: "json",
url: '@Url.Action("GetYears", "NewHome")'
}
}
},
index: 0,
change: onChange
});
return new JsonResult
{
Data = new SelectList(years, "newHomeIndexid", "selectedYear"),
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};