kendo mvc网格(主/详细)创建弹出式编辑器时出错,加载自定义编辑器

时间:2018-07-06 20:58:15

标签: asp.net-mvc kendo-grid kendo-asp.net-mvc

概述

当页面加载时,主从功能起作用(行扩展并检索子数据),但是单击New按钮(应使用自定义编辑器触发弹出窗口)时发生错误。

行为注释...单击New按钮后,展开的行消失。

剑道

版本:2017.3.913

Chrome控制台中的错误

  Uncaught ReferenceError: ConfigurationType is not defined

     (function anonymous(data) {
        var $kendoOutput, $kendoHtmlEncode = kendo.htmlEncode;
        with(data) {
          $kendoOutput = '<tr class="k-master-row" data-uid="' + (data.uid) + '" role=\'row\'><td class="k-hierarchy-cell"><a class="k-icon k-i-expand" href="#" aria-label="Expand" tabindex="-1"></a></td><td style="display:none" role=\'gridcell\'>' + (data && data.dirty && data.dirtyFields && data.dirtyFields.Id ? '<span class="k-dirty"></span>' : '') + '' + $kendoHtmlEncode(data.Id == null ? '' : data.Id) + '</td><td  role=\'gridcell\'>' + (data && data.dirty && data.dirtyFields && data.dirtyFields.Name ? '<span class="k-dirty"></span>' : '') + '' + $kendoHtmlEncode(data.Name == null ? '' : data.Name) + '</td><td  role=\'gridcell\'>' + (data && data.dirty && data.dirtyFields && data.dirtyFields.ConfigurationType ? '<span class="k-dirty"></span>' : '') + '' + (ConfigurationType.ConfigurationTypeName) + '</td><td  role=\'gridcell\'>' + (data && data.dirty && data.dirtyFields && data.dirtyFields.HasParentConfiguration ? '<span class="k-dirty"></span>' : '') + '' + $kendoHtmlEncode(data.HasParentConfiguration == null ? '' : data.HasParentConfiguration) + '</td><td  role=\'gridcell\'>' + (data && data.dirty && data.dirtyFields && data.dirtyFields.CanOverride ? '<span class="k-dirty"></span>' : '') + '' + $kendoHtmlEncode(data.CanOverride == null ? '' : data.CanOverride) + '</td><td  role=\'gridcell\'>' + (data && data.dirty && data.dirtyFields && data.dirtyFields.IsActive ? '<span class="k-dirty"></span>' : '') + '' + $kendoHtmlEncode(data.IsActive == null ? '' : data.IsActive) + '</td><td  class="k-command-cell" role=\'gridcell\'><a role="button" class="k-button k-button-icontext k-grid-edit"  title="Edit Configuration" href="#"><span class="k-icon k-i-edit"></span> </a><a role="button" class="k-button k-button-icontext k-grid-delete"  title="Delete Configuration" href="#"><span class="k-icon k-i-close"></span> </a></td></tr>';
        }
        return $kendoOutput;
     })

主网格

  @(Html.Kendo().Grid<ConfiguationViewModel>()
          .Name("configurationGrid")
          .Columns(columns =>
          {
              columns.Bound(c => c.Id).Width(150).Hidden(true);
              columns.Bound(c => c.Name);
              columns.Bound(c => c.ConfigurationType).ClientTemplate("#= ConfigurationType.ConfigurationTypeName  #").EditorTemplateName("ConfigurationType");
              columns.Bound(c => c.HasParentConfiguration);
              columns.Bound(c => c.CanOverride);
              columns.Bound(c => c.IsActive);
              columns.Command(command =>
              {
                  command.Edit().Text(" ").HtmlAttributes(new { title = "Edit Configuration" });
                  command.Destroy().Text(" ").HtmlAttributes(new { title = "Delete Configuration" });
              }).Width(210);
          })
          .ToolBar(toolbar => toolbar.Create().Text("New"))
          .Editable(editable => editable.Mode(GridEditMode.PopUp)
                                        .TemplateName("Configuration").Window(w => w.Width(640).Resizable(r => r.Enabled(true)))
                                        .ConfirmDelete("Are you sure you want to delete this configuration?")
                                        .DisplayDeleteConfirmation("Configuration deleted"))
          .Pageable(pager => pager
              .Input(false)
              .Numeric(true)
              .Info(true)
              .PreviousNext(true)
              .Refresh(true)
              .PageSizes(new[] { 10, 15, 20 }))
          .ClientDetailTemplateId("configDetailTemplate")
          .Sortable(sortable =>
          {
              sortable.SortMode(GridSortMode.SingleColumn);
          })
          .Scrollable(scrollable => scrollable.Enabled(false))
          .DataSource(dataSource => dataSource
              .Ajax()
              .PageSize(20)
              .Events(events => events.Error("handleErrors").Sync("sync_handler"))
              .Model(model => model.Id(c => c.Id))
              .Read(read => read.Action("Read", "Configuration"))
              .Create(create => create.Action("Create", "Configuration"))
              .Update(update => update.Action("Edit", "Configuration"))
              .Destroy(delete => delete.Action("Delete", "Configuration"))
          ))

详细模板

  <script id="configDetailTemplate" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<ConfigurationSettingViewModel>()
        .Name("grid_#=Id#") // template expression, to be evaluated in the master context
        .Columns(columns =>
        {
            columns.Bound(c => c.ConfigurationId).Title("Setting Id").Width(20);
            columns.Bound(c => c.Key).Width(250);
            columns.Bound(c => c.Value).Width(190);
        })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(5)
            .Read(read => read.Action("DetailTemplate_Configuration", "Configuration", new { configurationId = "#=Id#" }))
        )
        .Pageable()
        .Sortable()
        .ToClientTemplate())
  </script>     

“新”编辑器的视图模型

使用此模型创建视图时,编辑器cshtml被架设了

    public class ConfiguationViewModel
    {
        public int Id { get; set; }

        [Required]
        [MaxLength(255)]
        public virtual string Name { get; set; }
        [Required]
        public int ConfigurationTypeId { get; set; }
        [MaxLength(50)]
        public string Description { get; set; }
        [DisplayName("Parent Config Id")]
        public int? ConfigurationParentId { get; set; }
        public long? ModifiedById { get; set; }
        [Required]
        [DisplayName("Can Override")]
        public bool CanOverride { get; set; } = true;
        [Required]
        [DisplayName("Is Active")]
        public bool IsActive { get; set; } = true;
        [Required]
        public DateTime DateCreated { get; set; } = DateTime.UtcNow;
        public DateTime? DateModified { get; set; }

        [DisplayName("Has Parent Config")]
        public bool HasParentConfiguration => ConfigurationParentId.HasValue;
        [UIHint("ConfigurationType")]
        public ConfigurationTypeViewModel ConfigurationType { get; set; }

        public virtual ICollection<ConfigurationSettingViewModel> ConfigurationSettings { get; set; } = new HashSet<ConfigurationSettingViewModel>();
        public virtual ICollection<Rule> Rules { get; set; } = new HashSet<Rule>();


        public EmployeeViewModel Employee { get; set; }
        public  ConfiguationViewModel ParentConfiguration { get; set; }

      }

0 个答案:

没有答案