如何使用Kendo UI为MVC将DropDownList文本值绑定到另一个DropDownList?

时间:2015-02-26 01:01:45

标签: c# asp.net-mvc linq-to-entities kendo-asp.net-mvc

我使用的是用于ASP.NET MVC的Kendo UI,需要将下拉列表的选定值绑定到另一个下拉列表。我希望用户只显示适用于他们选择的状态选择的citiy条目。我的下拉列表如下:

<div id="bindcity" class="inr_div" data-bind="visible: showFromChooseCity">
  <h5 class="inr_hd">City<span>*</span>:</h5>
  @(Html.Kendo().DropDownList()
    .Name("fromCity")
    .DataTextField("name")
    .DataValueField("id")
    .DataSource(source =>
    {
      source.Read(read =>
      {
        read.Action("GetCity", "Quote");
      })
      .ServerFiltering(true);
    })
    .SelectedIndex(0)
  )

我按如下方式设置了几个控制器类:

    public JsonResult GetZips()
    {
        FreightEntities freight = new FreightEntities();
        var zips = freight.ZipCodes.AsQueryable();
        var city = freight.ZipCodes.AsQueryable();
        if (city != null)
        {
            zips = zips.Where(z => z.Zip = zips);
        }
        return Json(freight.ZipCodes.Select(z => new {Zip = z.Zip}), JsonRequestBehavior.AllowGet);
    }

    public JsonResult GetCity()
    {
        FreightEntities freight = new FreightEntities();
        var state = freight.ZipCodes.AsQueryable();
        var city = freight.ZipCodes.AsQueryable();
        if (state != null)
        {
            city = city.Where(s => s.State = state);
        }
        return Json(freight.ZipCodes.Select(s => new { State = s.State }), JsonRequestBehavior.AllowGet);

    }

    public JsonResult GetState()
    {
        FreightEntities freight = new FreightEntities();
        return Json(freight.ZipCodes.Select(s => new {State = s.State }), JsonRequestBehavior.AllowGet);
    }

上面的代码现在给出错误:

Cannot implicitly convert type 'System.Linq.IQueryable<FRCV2.Models.ZipCode>' to 'string'

由于我未在我的实体中使用ID字段,比较上述字段的适当方法是什么? 如何实现此级联下拉列表效果?

0 个答案:

没有答案