2016-04-19 68 views
1

这里是我的网是什么样子:添加下拉菜单剑道UI电网编辑模式 - C#MVC

@(Html.Kendo().Grid(Model).Name("Short-Grid").TableHtmlAttributes(new { @class = "short-duration-grid" }) 
     .Columns(col => 
     { 

      //Commands btn 
      col.Command(command => 
      { 
       command.Edit().HtmlAttributes(new { title = "Assign Analyst" }).CancelText(""); 
       command.Custom("Close").HtmlAttributes(new { title = "Close Attack" }); 

      }); 

      col.Bound(c => c.SDHandledBy).Title("User"); 
    }) 
    .Editable(editable => editable.TemplateName("AttackViewModel").Mode(GridEditMode.InLine)) 
    .Scrollable(o => o.Height(height)) 
    .HtmlAttributes(new { style = "height:700px;" }) 
    .DataSource(dataSource => dataSource 
     .Ajax() 
     .PageSize(20) 
     .Events(events => events.Error("error_handler")) 
     .Model(model => model.Id(o => o.AttackID)) 
     .Model(model => model.Field(f => f.SDHandledBy).Editable(true)) 
     .Create(update => update.Action("EditingInline_Create", "Grid")) 
     .Update(update => update.Action("Update", "ShortDuration")) 
     .Read(read => read.Action("EditingInline_Read", "Grid")) 
     .Destroy(update => update.Action("EditingInline_Destroy", "Grid")) 

    )   
     .Sortable() 
     .Groupable() 
     .Filterable() 
) 

我想在编辑模式下,以“用户”列中添加下拉菜单。 我在viewbag中有用户的相关数据。

如何更改代码,并使该列与viewbag中的数据一起显示为下拉菜单?

这可能吗?如果没有,请帮助我解释什么是最好的方法。

回答

1

~/Views/Shared/EditorTemplates创建一个视图并将其命名为说... Users

@using System.Collections 
@using Kendo.Mvc.UI 

@(Html.Kendo().DropDownList() 
.BindTo((IEnumerable)ViewBag.Users) 
.OptionLabel("... Select User ... ") 
.DataValueField("UserId") 
.DataTextField("UserName") 
.Name("UserId") 
) 

,并使用该视图EditorTemplate

columns.Bound(c => c.SDHandledBy).EditorTemplateName("Users") 
     .Title("Users").ClientTemplate("#:UserName#"); 

而且在添加UserNameDTO(假设SDHandledBy是类型GUID