我的母版页中有一些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:内容放在我的视图中,我不想将它链接到母版页中,而是在GenericControl中。
显然,我不能使用ContentPlaceHolder。我正在尝试使用PlaceHolder,但是我有一些问题要找出如何使用它。
发布于 2013-04-15 09:39:14
如果您使用的是Asp.net MVC,则不应该使用服务器控件(以<asp: />开头的服务器控件)。
请使用Razor在asp.net mvc中定义占位符,您可以这样做:
在_Layout中
@RenderSection("header", required: false)在望
@section header {
<h1>Hello World</h1>
}要使它在web窗体视图引擎中工作,您可能必须用@替换<% %>。
https://stackoverflow.com/questions/16011865
复制相似问题