【问题标题】:Kendo multi select binding is not working剑道多选绑定不起作用
【发布时间】:2016-01-20 12:40:40
【问题描述】:

我正在为我的 MVC 应用程序使用 kendo 多选控件,我在其中尝试绑定多选但它不起作用。 下面是我的html代码:

@(Html.Kendo().MultiSelect()
    .Name("ajaxTags")
    .Placeholder("Select cities...")
    .AutoBind(false)
    .DataTextField("CityName")
    .DataValueField("CityCode")
    .Filter(FilterType.StartsWith) 
    .BindTo(new SelectList("CityCode","CityName")) 
    .DataSource(source =>
     {
        source.Read(read =>
        {
            read.Action("GetCities", "DutyTravel"); 
        });
        source.ServerFiltering(true);                       
     })
     .HtmlAttributes(new { style = "width: 60%;" })
 )

所以,我在这里使用AutoBind(false),所以只有当用户展开时,它才会调用服务器并获取数据。

下面是我的控制器代码:

public JsonResult GetCities([DataSourceRequest] DataSourceRequest request)
{    
     List<DutyTravelPerDiemMaster> lstCities = null;
     lstCities = (List<DutyTravelPerDiemMaster>)HttpContext.Session["GetPerdiemList"];
     var lstFilteredCity = from d in lstCities
                               select new
                               {
                                   CityCode = d.CityCode,
                                   CityName = d.CityName
                               };


     return Json(lstFilteredCity.ToList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

在这种方法中,我看到所有城市代码和城市名称都在填充,但没有显示在多选中。

【问题讨论】:

    标签: asp.net-mvc kendo-ui kendo-asp.net-mvc


    【解决方案1】:

    您正在尝试将ServerAjax 绑定在一起。假设您要进行 Ajax 绑定,请删除此行:

    .BindTo(new SelectList("CityCode","CityName")) 
    

    【讨论】:

    • 您好 mmilican,感谢您的回复,我删除了这一行并添加了这一行 .Value((IEnumerable)ViewData["cityValues"]) 此处查看数据值我正在从 json 结果存储但仍然无法正常工作。
    【解决方案2】:

    根据 Teleriks Kendo UI demo,不需要设置 bindTo 属性。看看这段代码,它是从他们的演示部分复制和粘贴的:

    @(Html.Kendo().MultiSelect()
          .Name("products")
          .DataTextField("ProductName")
          .DataValueField("ProductID")
          .Placeholder("Select products...")   
          .AutoBind(false)       
          .DataSource(source => {
              source.Read(read =>
              {
                  read.Action("GetProducts", "Home");
              })
              .ServerFiltering(true);
          })
    )
    

    欲了解更多信息,请访问:http://demos.telerik.com/aspnet-mvc/multiselect/serverfiltering

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 2016-06-06
      • 2016-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多