我正在尝试通过本文档的帮助将下拉列表添加到kendo网格中 : http://demos.telerik.com/aspnet-mvc/grid/editing-custom
实际上我按照完全相同的方式但是没有机会我想知道kendo网格如何理解它必须在clientTemplate中放置一个下拉列表?! clientTemplate必须在某处定义吗?
答案 0 :(得分:1)
您必须通过将其添加到网格.ClientDetailTemplateId("template")
来定义clientTemplate
然后,您可以将DropDownList添加到模板中
<script id="template" type="text/kendo-tmpl">
@(Html.Kendo().DropDownList()
//build the dropdownlist
.ToClientTemplate()
)
</script>
答案 1 :(得分:0)
只需添加答案,这是一个较晚的答案...
例如...
columns.ForeignKey(x => x.ChangeTypeId,Model.ChangeTypes,“ Id”, “ ChangeTypeName”)
样品视图:
@(Html.Kendo().Grid<ChangeRequest>()
.Columns(columns =>
{
columns.Bound(x => x.Id)
.Visible(false);
columns.Bound(x => x.Description)
.Title("Description")
.Width(100);
columns.ForeignKey(x => x.ChangeTypeId, Model.ChangeTypes, "Id", "ChangeTypeName")
.Title("Data Type")
.Width(50);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(100);
})
.Name("gridChangeRequest")
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
.BindTo(Model.RTUDeviceCustomRegisterModbuses)
.DataSource(dataSource => dataSource.Ajax()
.ServerOperation(true)
.PageSize(50)
.Model(model => { model.Id(m => m.Id); })
.Create(update => update.Action("Create", "ChangeRequest", new { Area = "Documents" }))
.Update(update => update.Action("Update", "ChangeRequest", new { Area = "Documents" }))
.Destroy(update => update.Action("Destroy", "ChangeRequest", new { Area = "Documents" }))
)
.HtmlAttributes(new { @class = "", @style = "height: 400px;" }))
样品视图模型:
public class ChangeRequestFormViewModel : ViewModelBase
{
#region <Constructors>
public ChangeRequestFormViewModel(IApplication application) : base(application)
{
InitializeCreateEmpty();
}
#endregion
#region <Properties>
public ChangeRequestDocument Entity { get; set; }
#region lookups
public List<ChangeType> ChangeTypes { get; set; }
#endregion
#endregion
#region <Methods>
private void InitializeCreateEmpty()
{
var builder = Application.ChangeRequestDocumentXmlDataSetBuilder; //<-- This object is specific to my (particular) application
var dataset = builder.CreateEmpty();
Entity = dataset.Form;
ChangeTypes = dataset.ChangeTypes;
}
#endregion
}