2016-04-19 65 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