组织ASP MVC网站

时间:2013-03-21 05:38:38

标签: asp.net asp.net-mvc

我是ASP MVC的新手。

我正在尝试建立一个包含页眉,页脚,菜单和主要内容位置的网站。

最好的方法是什么? 部分观点,区域?

由于

2 个答案:

答案 0 :(得分:3)

使用layout.chtml文件,这将作为您网站的母版页面,并可用于您的所有视图。

对于MVC3,您可能会看到:ASP.NET MVC 3: Layouts and Sections with Razor

  

什么是布局?
  您通常希望在网站/应用程序的所有页面中保持一致的外观。   ASP.NET 2.0引入了“母版页”的概念,这有助于   在使用基于.aspx的页面或模板时启用此功能。剃刀也   支持这个概念的功能称为“布局” - 允许   你定义一个常见的网站模板,然后继承它的外观和   感受您网站上的所有观看次数/页面。

答案 1 :(得分:3)

您可以使用页眉和页脚的部分视图。对于我的大多数Asp.Net MVC项目,我在母版页中使用部分视图。您可以在标题部分视图中添加菜单。

<body>   
<div class="contentdiv">
<% Html.RenderPartial("Header"); %>
<div class="row-fluid">
<div class="container containerbg" >
    <asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</div>
<% Html.RenderPartial("Footer"); %>
<asp:ContentPlaceHolder ID="ScriptsSection" runat="server" />
</div> 
</body>
相关问题