如何在ASP.NET中创建两个具有相同ID的ContentPlaceHolder?
|
我不想有两个母版页,所以我想这样做(省略<%%>以提高可读性):
if (a == b)
{
<asp:ContentPlaceHolder ID=\"X\" runat=\"server\" />
}
else
{
<div class=\"c\">
<asp:ContentPlaceHolder ID=\"X\" runat=\"server\" />
</div>
}
但这不会让我:
Duplicate ContentPlaceHolder \'X\' were found. ContentPlaceHolders require unique IDs.
因此,我尝试设置ID为ID = \“ <%= \” X \“%> \”的ID,不,也不会让我:
Server tags cannot contain <% ... %> constructs.
然后,我尝试<%#Eval(\“ X \”)%>并没有:
The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: <asp:Button runat=\"server\" id=\"Button1\" />
有什么方法可以实现我的目标?我在想类似
echo \'<asp:ContentPlaceHolder ID=\"X\" runat=\"server\" />\'
或是一种动态的方式添加标签,因为解析器显然无法识别if else块,该if else块不会让两个标签具有相同的ID。
我正在将MVC与默认视图引擎一起使用。
没有找到相关结果
已邀请:
1 个回复
凸晴