我试图实现两级深度的Kendo小部件,但是Razor引擎一直抱怨:“内联标记块(@Content)不能嵌套。只允许一级内联标记。”
Razor引擎是否有办法将助手呈现两级深度?
我的代码示例:
@(Html.Kendo().TabStrip()
.Name("tabStrip")
.Items(tabstrip =>
{
tabstrip.Add().Text("Strip1")
.Selected(true)
.Content(@<text>
@RenderPanelBar()
</text>);
tabstrip.Add().Text("Strip2")
.Content(@<text>
</text>);
})
)
@helper RenderPanelBar(){
@(Html.Kendo().PanelBar()
.Name("panelBar")
.ExpandMode(PanelBarExpandMode.Single)
.Items(panelbar =>
{
panelbar.Add().Text("panel1")
.Expanded(true)
.Content(@<div>
<div>
@(Html.Kendo().Grid<GroupViewModel>()
.Name("GroupGrid")
.Columns(columns =>
{
columns.Bound(c => c.GroupID).Hidden();
columns.Bound(c => c.Name);
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Template(@<text>
@RenderDropDown() //<-- here the error occurs
</text>);
}
)
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Scrollable(s => s.Enabled(false))
.Selectable(s => s.Enabled(true).Mode(GridSelectionMode.Single))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Group_Grid_Read", "Home"))
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.GroupID))
.Create(update => update.Action("EditingInline_Create", "Home"))
.Update(update => update.Action("EditingInline_Update", "Home"))
.Destroy(update => update.Action("EditingInline_Destroy", "Home"))
)
.Events(e => e.Change("onGroupGridChange").Save("GroupGrid_Save"))
)
</div>
</div>
</div>);
panelbar.Add().Text("panel2")
.Content(@<div>
//stuff abbreviated
</div>
);
})
)
}
@helper RenderDropDown(){
<div class="toolbar">
<label class="category-label" for="category">Show products by category:</label>
@(Html.Kendo().DropDownList()
.Name("categories")
.OptionLabel("All")
.DataTextField("CategoryName")
.DataValueField("CategoryID")
.AutoBind(false)
.Events(e => e.Change("categoriesChange"))
.DataSource(ds =>
{
ds.Read("ToolbarTemplate_Categories", "Grid");
})
)
</div>
}
答案 0 :(得分:13)
我认为您可能需要在任何级别使用剃刀助手。在您的情况下,您可能需要将网格放在另一个RenderGrid()
中,如下所示:
@(Html.Kendo().TabStrip()
.Name("tabStrip")
.Items(tabstrip =>
{
tabstrip.Add().Text("Strip1")
.Selected(true)
.Content(@<text>
@RenderPanelBar()
</text>);
tabstrip.Add().Text("Strip2")
.Content(@<text>
</text>);
})
)
@helper RenderPanelBar()
{
@(Html.Kendo().PanelBar()
.Name("panelBar")
.ExpandMode(PanelBarExpandMode.Single)
.Items(panelbar =>
{
panelbar.Add().Text("panel1")
.Expanded(true)
.Content(@<text>
@RenderGrid()
</text>
);
panelbar.Add().Text("panel2")
.Content(@<div>
//stuff abbreviated
</div>
);
})
)
}
@helper RenderGrid()
{
@(Html.Kendo().Grid<UserModel>()
.Name("GroupGrid")
.Columns(columns =>
{
columns.Bound(c => c.GroupID).Hidden();
columns.Bound(c => c.Name);
columns.Command(command =>
{
command.Edit();
command.Destroy();
});
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Template(@<text>
@RenderDropDown()
</text>);
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Scrollable(s => s.Enabled(false))
.Selectable(s => s.Enabled(true).Mode(GridSelectionMode.Single))
.DataSource(dataSource => dataSource.Ajax()
.Read(read => read.Action("Group_Grid_Read", "Home"))
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.GroupID))
.Create(update => update.Action("EditingInline_Create", "Home"))
.Update(update => update.Action("EditingInline_Update", "Home"))
.Destroy(update => update.Action("EditingInline_Destroy", "Home")))
.Events(e => e.Change("onGroupGridChange").Save("GroupGrid_Save"))
)
}
@helper RenderDropDown()
{
<div class="toolbar">
<label class="category-label" for="category">Show products by category:</label>
@(Html.Kendo().DropDownList()
.Name("categories")
.OptionLabel("All")
.DataTextField("CategoryName")
.DataValueField("CategoryID")
.AutoBind(false)
.Events(e => e.Change("categoriesChange"))
.DataSource(ds => { ds.Read("ToolbarTemplate_Categories", "Grid"); })
)
</div>
}