0

我有我的母版页,里面有一些 Html.RenderPartial 和一个随机的 ContentPlaceHolder,或多或少像这样:

<body>

<% Html.RenderPartial("Controls/Menu"); %>
<% Html.RenderPartial("Controls/GenericControl"); %>
<asp:ContentPlaceHolder ID="MyContent" runat="server" />

</body>

目前在Menu.ascx文件中,我有一个按钮列表。在GenericControl.ascx文件中有一些按钮来管理内容。
我的菜单中有与按钮一样多的视图,内容是这样描述的:

<asp:Content ID="Content1" ContentPlaceHolderID="MyContent" runat="server">
<div>Some divs here</div>
<asp:Content>

这是我的问题。我想在我的视图中添加另一个asp:Content,我不想在母版页中链接它,而是在 GenericControl 中。
显然我不能使用 ContentPlaceHolder。我正在尝试改用 PlaceHolder,但在查找如何使用它时遇到了一些问题。

4

1 回答 1

5

如果您使用的是 Asp.net MVC,则不应使用服务器控件(以 开头的控件<asp: />)。

使用 Razor 引擎在 asp.net mvc 中定义占位符,你可以这样做:

在_布局中

@RenderSection("header", required: false)

在视图中

@section header {
   <h1>Hello World</h1>
}

要使其在 Web 表单视图引擎中工作,可能您必须替换@<% %>

于 2013-04-15T09:39:14.423 回答