0

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

匹配视图模型:

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

国家型号:

  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"))     
    ))      

控制器:

在控制器中,我将列表分配给 ViewBag.Countries。我检查了我是否在 ViewBag 中获取列表。

4

1 回答 1

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

于 2014-05-05T20:25:25.617 回答