MVC3 Razor @RenderSection

Mvc3的Razor视图引擎还提供了@RenderSection

@RenderSection在母版页中占个位,然后让使用此母版页的子页自己去呈现他们的Section。

母版页_Layout.cshtml中定义@RenderSection("Section名")

<body>
    <div id="header">@{Html.RenderAction("Menu", "Global");}</div>
    <div id="sideBar">
      @RenderSection("SubMenu")
    </div>
    <div id="container">@RenderBody()</div>
    <div id="footer">@{Html.RenderAction("Footer", "Global");}</div>
</body>

添加一个About.cshtml,使用_Layout.cshtml做母版页

然后就可以在About.cshtml中定义"SubMenu"要呈现的内容

@{
    ViewBag.Title = "About";
 }

 @section SubMenu{
    Hello This is a section implement in About View.
 }

  

 

posted on 2013-12-08 11:58  风景依旧  阅读(286)  评论(0编辑  收藏  举报