在编辑模式下将下拉菜单添加到 Kendo UI 网格 - C# MVC
Adding dropdown menu to Kendo UI grid in editing mode - 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()
)
我正在尝试将编辑模式下的下拉菜单添加到 "User" 列。
我在viewbag里面有用户的相关数据
我怎样才能更改代码,并使此列显示为带有来自 viewbag 的数据的下拉列表?
可能吗?如果没有,请帮助我并解释什么是最好的方法。
在 ~/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#");
并在您的 DTO
中添加 UserName
(假设 SDHandledBy
是 GUID
的类型)
这是我的网格的样子:
@(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()
)
我正在尝试将编辑模式下的下拉菜单添加到 "User" 列。 我在viewbag里面有用户的相关数据
我怎样才能更改代码,并使此列显示为带有来自 viewbag 的数据的下拉列表?
可能吗?如果没有,请帮助我并解释什么是最好的方法。
在 ~/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#");
并在您的 DTO
中添加 UserName
(假设 SDHandledBy
是 GUID
的类型)