Why Kendo DropDownList can not be initialized by json result from controller action

笑着哭i 提交于 2019-12-12 03:25:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!