Telerik的Kendo Grid组件,指定了GridEditMode.Popup和TemplateName

时间:2014-07-07 15:02:54

标签: c# telerik kendo-grid

我的观点如下:

@model Wellbore
@(Html.Kendo().Grid<WellboreSection>()
        .Name("wellboresectiongrid")
        .Columns(columns =>
        {
            columns.Bound(p => p.Name);
            columns.Bound(p => p.Lenght);
            columns.Bound(p => p.SectionNumber);
            columns.Bound(p => p.Volume);
            columns.Bound(p => p.HoleDiameter);
            columns.Command(command =>
            {
                command.Edit();
                command.Destroy();
            }).Width(240);
        })
        .ToolBar(toolbar => toolbar.Create())
        .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("WellboreSectionPopupTemplate"))
        .Sortable()
        .Scrollable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(10)
            .Events(events => events.Error("KendoGrid.ErrorHandler"))
            .Model(model => model.Id(p => p.Id))
            .Create(create => create.Action("WellboreSection_Create", "WellboreSection",
                new RouteValueDictionary(new Dictionary<string, object>() { { "wellboreId", Model.Id } })))
            .Read(read => read.Action("WellboreSection_Read", "WellboreSection",
                    new RouteValueDictionary(new Dictionary<string, object>() { { "wellboreId", Model.Id } })))
            .Update(update => update.Action("WellboreSection_Update", "WellboreSection",
                    new RouteValueDictionary(new Dictionary<string, object>() { { "wellboreId", Model.Id } })))
            .Destroy(destroy => destroy.Action("WellboreSection_Destroy", "WellboreSection",
                    new RouteValueDictionary(new Dictionary<string, object>() { { "wellboreId", Model.Id } })))
      ))

一个看起来像这样的WellboreSectionPopupTemplate.cshtml文件:

@model WellboreSection
blaaaaah!!!

但是,当我在网格中单击编辑时,会显示包含该对象的所有字段的弹出窗口。

令我感到困惑的是,我有另一个看起来像这样的网格:

<div class="container">
    <div class="row">
        <div class="col-md-12 sl-table">
            @(Html.Kendo().Grid<Customer>()
                  .Name("grid")
                  .Columns(columns =>
                  {
                      columns.Bound(p => p.Name);
                      columns.Bound(p => p.StreetAddress);
                      columns.Bound(p => p.ZipCode);
                      columns.Bound(p => p.City);
                      columns.Bound(p => p.State);
                      columns.Bound(p => p.Country);
                      columns.Bound(p => p.MainPhoneNumber);
                      columns.Bound(p => p.ContactPerson);
                      columns.Bound(p => p.ContactPersonEmail);
                      columns.Bound(p => p.ContactPersonPhone);
                      columns.Bound(p => p.ContactPersonPhone2);
                      columns.Command(command =>
                      {
                          command.Edit();
                          command.Destroy();
                      }).Width(180);
                  })
                  .ToolBar(toolbar => toolbar.Create())
                  .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("CustomerPopUpTemplate"))
                  .Pageable()
                  .Sortable()
                  .Scrollable()
                  .HtmlAttributes(new {style = "height:500px;"})
                  .DataSource(dataSource => dataSource
                      .Ajax()
                      .PageSize(10)
                              .Events(happening => happening.Error("KendoGrid.ErrorHandler"))
                      .Model(model => model.Id(p => p.Id))
                      .Create(update => update.Action("EditingPopup_Create", "CustomerManagement"))
                      .Read(read => read.Action("EditingPopup_Read", "CustomerManagement"))
                      .Update(update => update.Action("EditingPopup_Update", "CustomerManagement"))
                      .Destroy(destroy => destroy.Action("EditingPopup_Destroy", "CustomerManagement"))))
        </div>
    </div>
</div> 

实际上显示模板100%正确。我检查了浏览器,当我单击网格中的编辑或添加新按钮时,它不会调用WellboreSectionPopupTemplate。我可能会失踪什么?

  • 如果需要更多信息,请询问,我很乐意提供:)

1 个答案:

答案 0 :(得分:8)

在MVC中创建自定义模板时,它们可以放置在某个位置。

搜索的位置是:

  • /地区/ AREANAME /查看/ ControllerName / EditorTemplates / TEMPLATENAME
  • /地区/ AREANAME /查看/共享/ EditorTemplates / TEMPLATENAME
  • /查看/ ControllerName / EditorTemplates / TEMPLATENAME
  • /查看/共享/ EditorTemplates / TEMPLATENAME

显示模板路径是相同的,只是在路径中使用/ DispayTemplates /而不是/ EditorTemplates /

模板名称也必须匹配约定:

  • ModelMetadata的TemplateHint
  • ModelMetadata的DataTypeName
  • 类型名称
  • 如果对象不复杂:“String”
  • 如果对象很复杂且界面:“对象”
  • 如果对象很复杂而不是接口:通过继承hiearchy递归该类型,尝试每个类型名称

来源:http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html