1

在 MVC4 中,我想在两个不同的页面上显示不同内容的页脚,以实现适合的功能,部分或任何更好的解决方案?

4

1 回答 1

3

看起来很简单。

Layout.cshtml(不管你怎么称呼它)

<html>
<body>

  <div id="bodyContent">
    // content
    @RenderBody()
  </div>

  <div id="footer">
  @if (IsSectionDefined("customFooter")) // optional
  {    
    @RenderSection("customFooter")
  }
  else // optional
  {
    <div> standard footer </div>
  }
  </div>
</body>
</html>

所有没有 customFooter 的页面都将呈现标准页脚。

页脚 1

@Section customFooter
{
  <div>Custom Footer 1</div>
}

页脚 2

@Section customFooter
{
  <div>Custom Footer 2</div>
}

这允许您将页脚放置在布局中的任何位置,而不仅仅是在 RenderBody() 的底部。

于 2013-09-13T20:04:50.930 回答