【问题标题】:No drop down is shown when using columns.ForeignKey in kendo grid在剑道网格中使用 columns.ForeignKey 时不显示下拉菜单
【发布时间】:2023-04-11 08:14:01
【问题描述】:

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

MatchViewModel:

  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 中获取列表。

【问题讨论】:

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


    【解决方案1】:

    尝试改变

    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 的集合

    【讨论】:

    • 这不起作用,因为该参数不采用非通用版本的 IEnumerable。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    相关资源
    最近更新 更多