简体   繁体   English

使用column.ForeignKey时不会显示下拉列表

[英]No drop down is shown when using columns.ForeignKey in kendo grid

In kendo grid, when I use columns.ForeignKey, I am not getting a drop down. 在kendo网格中,当我使用column.ForeignKey时,我不会下拉菜单。 I actually need a drop down with the list of countries. 我实际上需要下拉列表中的国家/地区。 Where do I go wrong!! 我哪里出错了! Pls help. 请帮助。 I have included the model,view and the controller. 我已经包括了模型,视图和控制器。

MatchViewModel: MatchViewModel:

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

CountryModel: 国家模型:

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

This is my view 这是我的看法

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

Controller: 控制器:

In controller I am assigning List to ViewBag.Countries.I have checked that I am getting the list in ViewBag. 在控制器中,我正在将List分配给ViewBag.Countries。我检查了是否在ViewBag中获得了列表。

Try changining 尝试换尿布

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

to

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

assuming the Enumerable is a collection of Country 假设Enumerable是Country的集合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM