2013-04-15 42 views
0

我有我的一些Html.RenderPartial和裏面隨機的ContentPlaceHolder,或多或少像這樣的母版頁:Asp.net-mvc PlaceHolder,如何使用它?

<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,但我遇到了一些問題以找到如何使用它。

回答

5

如果您使用Asp.net MVC,則不應使用服務器控件(以<asp: />開頭的那些控件)。

做用剃刀引擎定義在asp.net mvc的佔位符,你可以這樣做:

在_layout

@RenderSection("header", required: false) 

鑑於

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

,使其在Web表單工作查看引擎,可能你必須用<% %>替換@

+0

我的專業版用幾句話來說,瑕疵是他們給了我那些文件,他們說:「讓這個網站工作,並使其好看!」 而且我仍然在學習這個_logic_是如何工作的。 無論如何感謝您的答案,我會嘗試你的建議。 – krvl