2
我不想有兩個母版頁,所以我想這樣做(留出了<%%>的可讀性):如何在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「 %>」 不,不會讓我可以:
Server tags cannot contain <% ... %> constructs.
然後我試圖<%#的eval(」 X「)%>和n開放:
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塊,不會讓兩個標籤具有相同的ID。
我使用默認視圖引擎的MVC。
優秀。這就是爲什麼 - 我不認爲這個答案。 – sker 2011-06-13 15:34:21