【问题标题】:Adding DropDownList to kendo grid in MVC在 MVC 中将 DropDownList 添加到剑道网格
【发布时间】:2015-01-29 23:15:57
【问题描述】:

我正在尝试借助本文档将下拉列表添加到剑道网格 : http://demos.telerik.com/aspnet-mvc/grid/editing-custom

实际上我遵循了完全相同的方式,但没有机会我想知道剑道网格如何理解它必须在 clientTemplate 中放置一个下拉列表?! clientTemplate 必须在某处定义吗?

【问题讨论】:

    标签: asp.net-mvc kendo-ui grid html.dropdownlistfor client-templates


    【解决方案1】:

    您必须通过将其添加到 Grid .ClientDetailTemplateId("template") 来定义一个 clientTemplate
    然后你可以在模板中添加 DropDownList

    <script id="template" type="text/kendo-tmpl">
        @(Html.Kendo().DropDownList()
           //build the dropdownlist
           .ToClientTemplate()
        )
    </script>
    

    演示:http://demos.telerik.com/aspnet-mvc/grid/detailtemplate

    【讨论】:

    • 我想将下拉列表放在表格的一列中,比如说第 3 列,那么在这种情况下,建议的解决方案如何知道将下拉列表放在哪里?
    【解决方案2】:

    只是为了增加答案,这是一个迟到的答案......

    • 在您的 ViewModel 中创建一个列表
    • 将您的 Model.PropertyId 视为外键

    例如...

    columns.ForeignKey(x => x.ChangeTypeId, Model.ChangeTypes, "Id", "更改类型名称")

    示例视图:

    @(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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-27
      • 2023-03-10
      • 1970-01-01
      相关资源
      最近更新 更多