问题
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);
}
But dropdownlist is filled with [object object]. After adding following to Html.Kendo().DropDownList()
.DataTextField("Description")
.DataValueField("Id")
dropdownlist is filled with [undefined]. I need help on this. Thanks.
回答1:
After changing DisciplinesBySportAjax() to
public JsonResult DisciplinesBySportAjax(string sportId)
{
var sports = this._sportBL.GetDisciplinesBySport(sportId);
return Json(sports, JsonRequestBehavior.AllowGet);
}
It works fine, despite it still needs DataTextField("Description") and DataValueField("Id").
来源:https://stackoverflow.com/questions/28448824/why-kendo-dropdownlist-can-not-be-initialized-by-json-result-from-controller-act