gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:56:48 25 4
gpt4 key购买 nike

我有一个看起来像这样的 View :

@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。我可能会遗漏什么?

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

最佳答案

在 MVC 中创建自定义模板时,它们必须放置在特定位置。

搜索到的位置是:

  • /Areas/AreaName/Views/ControllerName/EditorTemplates/TemplateName
  • /Areas/AreaName/Views/Shared/EditorTemplates/TemplateName
  • /Views/ControllerName/EditorTemplates/TemplateName
  • /Views/Shared/EditorTemplates/TemplateName

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

模板名称也必须符合约定:

  • 来自模型元数据的模板提示
  • 来自模型元数据的数据类型名称
  • 类型名称
  • 如果对象不复杂:“String”
  • 如果对象很复杂并且有一个接口(interface):“Object”
  • 如果对象很复杂且不是接口(interface):通过类型的继承层次递归,尝试每个类型名称

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

关于c# - Telerik 的 Kendo Grid 组件,指定了 GridEditMode.Popup 和 TemplateName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24613759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com