【问题标题】:Unable to bind drop down list in telerik kendo mvc grid无法绑定 Telerik kendo mvc 网格中的下拉列表
【发布时间】:2014-11-08 10:51:13
【问题描述】:

我在 Telerik mvc 剑道网格中绑定下拉列表时遇到了困难。

我有一组绑定到网格的记录,每条记录都有一个 Foregin Key 属性。目前它正在下拉应该在的地方呈现一个文本框。

我已经通过 Telerik 文档和演示代码进行了搜索,他们有一个有效的下拉菜单,但是它只在该字段上使用 ClientTemplate 显示它们,并且不显示该模板的代码。

在我的控制器操作中,我使用我的集合填充 ViewData,如下所示:

 IEnumerable<DetailSlotDTO> slots = Mapper.ToDTO(detailSlotRepository.GetAll());
 ViewData["Slots"] = slots;

而DetailSlotDTO类如下:

 public class DetailSlotDTO
 { 
    public int Id { get; set; }
    public string Description { get; set; }
 }

然后我尝试在我的视图中设置网格,如下所示:

 @(Html.Kendo().Grid<SFT.Web.DTOs.SyndicatedRecordDTO>()
.Name("slotGrid")
.Columns(c =>
{
    c.Bound(f => f.DetailSlot).ClientTemplate(Html.Kendo().DropDownList()
        .BindTo(ViewData["Slots"] as IEnumerable<SFT.Web.DTOs.DetailSlotDTO>)
        .Name("SlotDesc_#=Id#")
        .DataTextField("Description")
        .DataValueField("Id")
        .ToClientTemplate().ToHtmlString()
        );
    c.Bound(f => f.Client);
    c.Bound(f => f.Product);
    c.Bound(f => f.Start);
    c.Bound(f => f.End);
    c.Bound(f => f.PurchaseOrder);
    c.Bound(f => f.Value);
    c.Bound(f => f.KPIPenalty);
    c.Bound(f => f.Notes);
})
.ToolBar(t =>
{
    t.Create();

})
.Editable(e => e.Mode(GridEditMode.InCell))
.DataSource(d => d
    .Ajax()
    .Batch(false)
    .ServerOperation(false)
    .Model(m =>
    {
        m.Id(r => r.Id);
        m.Field(r => r.DetailSlot);
        m.Field(r => r.Client).Editable(true);
        m.Field(r => r.Product).Editable(true);
        m.Field(r => r.Start).Editable(true);
        m.Field(r => r.End).Editable(true);
        m.Field(r => r.PurchaseOrder).Editable(true);
        m.Field(r => r.Value).Editable(true);
        m.Field(r => r.KPIPenalty).Editable(true);
        m.Field(r => r.Notes).Editable(true);
    })
    .Read(read => read.Action("SlotGrid_Read", "SalesFee", new { id = @Model.SalesFeeId }))
    .Create(create => create.Action("SlotGrid_Create", "SalesFee"))
    .Update(update => update.Action("SlotGrid_Update", "SalesFee"))
    .Destroy(destroy => destroy.Action("SlotGrid_Destroy", "SalesFee"))
)
)

对此的任何帮助将不胜感激。我昨天花了一整天的时间试图让它工作,但运气不佳。

提前谢谢你

【问题讨论】:

    标签: asp.net-mvc telerik telerik-grid


    【解决方案1】:

    如果您想在编辑模式下显示下拉菜单,则必须在 kendo Grid 中使用“ForeignKey”列。

    columns.ForeignKey(p => p.DetailSlot, (System.Collections.IEnumerable)ViewData["Slots"], "Id", "Description"); 
    

    请查看link,在这个链接中我已经发布了完整的代码和演示项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多