Kendo DropDownList没有填充

Zoinky

Kendo下拉列表由于某种原因是空的,我不确定,下面是我的所有代码

@(Html.Kendo().DropDownList()
      .Name("parties")
      .HtmlAttributes(new { style = "width: 250px" })
      .DataTextField("Name")
      .DataValueField("PartyId")
      .DataSource(source =>
      {
          source.Read(read =>
          {
              read.Action("GetParties", "Concept");
          });
      })
)

控制器呼叫

public JsonResult GetParties([DataSourceRequest] DataSourceRequest request)
    {
        var parties = MiscAdapter.GetParties().Select(x => new PartyModel
        {
            Name = x.PartyName,
            PartyId = x.PartyId
        });
        return Json(parties.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

模型

public class PartyModel
{
    public int PartyId { get; set; }
    public string Name { get; set; }
}

根据F12工具返回的数据

{"Data":[{"PartyId":1,"Name":"New Democratic Party"},{"PartyId":2,"Name":"Saskatchewan Party"},{"PartyId":3,"Name":"Liberal"},{"PartyId":4,"Name":"Green"},{"PartyId":5,"Name":"Independant"}],"Total":5,"AggregateResults":null,"Errors":null}

即使我看不到代码或返回的数据,下拉菜单也不会显示任何内容。

杰耶什·戈亚尼(Jayesh Goyani)

请尝试使用以下代码段。您已将其用于网格数据绑定的方法。

public JsonResult GetParties()
{
    List<PartyModel> models = new List<PartyModel>();
    models.Add(new PartyModel() { Name = "Name1", PartyId = 1 });
    models.Add(new PartyModel() { Name = "Name2", PartyId = 2 });

    return Json(models, JsonRequestBehavior.AllowGet);
}

让我知道是否有任何问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章