在kendo网格中使用columns.ForeignKey时不会显示下拉列表

时间:2014-05-05 13:13:38

标签: c# asp.net-mvc kendo-grid kendo-asp.net-mvc kendo-dropdown

在kendo网格中,当我使用columns.ForeignKey时,我没有得到下拉菜单。我实际上需要下载国家列表。我哪里出错!!请帮忙。我已经包含了模型,视图和控制器。

MatchViewModel:

  public short MatchID { get; set; }      
  public virtual Country Country1 { get; set; }    

CountryModel:

  public short CountryID { get; set; }       
  public string Name { get; set; }    

这是我的观点

@(Html.Kendo().Grid((System.Collections.Generic.IEnumerable<FootballPredictor.Models.Match        ViewModel>)ViewData["matches"])       
        .Name("grid")       
        .Columns(columns =>   
        {   
     columns.Bound(m => m.MatchID).Width(50);      
     columns.ForeignKey(m => m.Country1.Name, (IEnumerable)ViewBag.Countries, dataFieldText:     "Name", dataFieldValue: "CountryID");       
     columns.Command(command => { command.Edit(); command.Destroy(); }).Width(150);    
        }) .ToolBar(toolbar => toolbar.Create())      
       .Editable(editable => editable.Mode(GridEditMode.InLine))       
       .Editable(e => e.DisplayDeleteConfirmation("Are you sure to delete?"))      
       .HtmlAttributes(new { style = "height:280px;" })      
       .Pageable()      
       .Scrollable()      
       .DataSource(ds => ds     
       .Server()      
       .PageSize(10)     
       .Model(m =>      
       {      
           m.Id(p => p.MatchID);      
           m.Field(p => p.MatchID).Editable(false);       
     m.Field(p => p.Country1).Editable(true);      
      })      
      .Read(read => read.Action("Index", "Match"))      
       .Create(update => update.Action("Create", "Match"))      
       .Update(update => update.Action("Edit", "Match"))      
       .Destroy(update => update.Action("Delete", "Match"))     
    ))      

控制器:

在控制器中我将List分配给ViewBag.Countries.I已检查我在ViewBag中获取列表。

1 个答案:

答案 0 :(得分:0)

尝试改编

columns.ForeignKey(m => m.Country1.Name, (IEnumerable)ViewBag.Countries, dataFieldText:     "Name", dataFieldValue: "CountryID");       

columns.ForeignKey(m => m.Country1.Name, (IEnumerable<Country>)ViewBag.Countries, "Name", "CountryID");       

假设Enumerable是Country

的集合