为什么Kendo DropDownList无法通过控制器操作的json结果初始化 [英] Why Kendo DropDownList can not be initialized by json result from controller action
本文介绍了为什么Kendo DropDownList无法通过控制器操作的json结果初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Kendo DropDownlist,如下所示:
I have a Kendo DropDownlist as follow
<%= Html.Kendo().DropDownList()
.Name("AssignDisciplineId")
.DataSource(dataSource =>
{
dataSource.Read(read =>
{
read.Action("DisciplinesBySportAjax","Shared").Data("onDisciplinesBySportData");
});
})
.Events(events => events
.Change("onAssignDisciplineComboChanged")
)
.HtmlAttributes(new { style = "font-size:8pt;" })
%>
function onDisciplinesBySportData(e)
{
var sportId = $('#AssignSportsId').data('kendoDropDownList').value();
return { sportId: sportId }
}
public JsonResult DisciplinesBySportAjax(string sportId)
{
var sports = this._sportBL.GetDisciplinesBySport(sportId);
return Json(new SelectList(sports, "Id", "Description"), JsonRequestBehavior.AllowGet);
}
但是下拉列表中填充了[object object].将以下内容添加到Html.Kendo().DropDownList()
But dropdownlist is filled with [object object]. After adding following to Html.Kendo().DropDownList()
.DataTextField("Description")
.DataValueField("Id")
下拉列表用[undefined]填充.我需要这方面的帮助.谢谢.
dropdownlist is filled with [undefined]. I need help on this. Thanks.
推荐答案
将DisciplinesBySportAjax()更改为
After changing DisciplinesBySportAjax() to
public JsonResult DisciplinesBySportAjax(string sportId)
{
var sports = this._sportBL.GetDisciplinesBySport(sportId);
return Json(sports, JsonRequestBehavior.AllowGet);
}
即使它仍然需要DataTextField("Description")和DataValueField("Id"),它仍然可以正常工作.
It works fine, despite it still needs DataTextField("Description") and DataValueField("Id").
这篇关于为什么Kendo DropDownList无法通过控制器操作的json结果初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文