Child DropDownList在成功级联后不显示过滤数据

时间:2018-05-28 07:34:53

标签: kendo-asp.net-mvc cascadingdropdown kendo-dropdown

电贺!

我有一个涉及两个下拉列表的问题。父母以非常简单的方式运作。在父DDL中进行有效选择后,子DDL会自动启用,我会捕获一个带回正确JSON数据的XHR,但子DDL无法呈现该数据。

CSHTML:

@* Parent DDL *@
@(Html.Kendo().DropDownListFor(m=>m.AccountCode)
  .OptionLabel("Service Type...")
  .DataTextField("Name")
  .DataValueField("Code")
  .BindTo(ViewBag.AccountCodes)
  .HtmlAttributes(new { @class = "form-control", style = "width: 100%", required = "required" })
)

@* Child DDL *@
@(Html.Kendo().DropDownListFor(m => m.ServiceFinderId)
      .HtmlAttributes(new { @class = "form-control", style = "width: 100%" })
      .OptionLabel("Select service...")
      .DataTextField("Name").DataValueField("Id")
      .Filter(FilterType.Contains)
      .Height(450)
      .DataSource(source =>
      {
          source.Read(read =>
          {
              read.Action("GetAllServices", "AjaxApi").Type(HttpVerbs.Post)
                  .Data("ServiceFinderIdFilter");
          })
          .ServerFiltering(false);
      })
      .Enable(false)
      .AutoBind(false)
      .CascadeFrom(Html.IdFor(m => m.AccountCode).ToString())
)

的JavaScript

function ServiceFinderIdFilter() {
  return {
    accountCode: $("#" +'@Html.IdFor(m=>m.AccountCode)').val()
  };
}

C#

public async Task<JsonResult> GetAllServices(string accountCode)
{
    var result = await serviceClient.GetServiceList(true, null, string.Empty, new[] { accountCode });

    if (result == null)
    {
        return Json("", JsonRequestBehavior.AllowGet);
    }

    return Json(result.Select(s => new { Id = s.Code, Name = $"#{s.Code:D4} {s.Name}, Fee: {s.Fee:0.##}" }).ToList(), JsonRequestBehavior.AllowGet);
}

如果我调试,我可以看到从控制器发送了正确的结果集。在chrome中,XHR调用的响应也是很好的JSON。但是,最后,孩子DDL显示没有数据

0 个答案:

没有答案