为什么Kendo DropDownList无法通过控制器操作的json结果进行初始化

时间:2015-02-11 07:32:10

标签: kendo-ui kendo-dropdown

我有一个Kendo DropDownlist如下

<%= 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()

之后
.DataTextField("Description")
.DataValueField("Id")

下拉列表中填充了[undefined]。我需要帮助。谢谢。

1 个答案:

答案 0 :(得分:1)

将DisciplinesBySportAjax()更改为

public JsonResult DisciplinesBySportAjax(string sportId)
{
    var sports = this._sportBL.GetDisciplinesBySport(sportId);

    return Json(sports, JsonRequestBehavior.AllowGet);
}

它工作正常,尽管它仍然需要DataTextField(“Description”)和DataValueField(“Id”)。