MVC 3 - Nested layouts - sections don't render in Areas

后端 未结 2 2212
暗喜
暗喜 2021-02-20 07:45

Problem:

Given this nested layout structure:

~/Views/Shared/_layoutBase.cshtml
~/Views/Shared/_layout.cshtml

Where _layoutBase.cshtml i

2条回答
  •  长发绾君心
    2021-02-20 08:18

    I am unable to reproduce the problem. Here's my setup and steps I did.

    1. Create a new ASP.NET MVC 3 application using the Internet Application Template
    2. Add ~/Views/Shared/_LayoutBase.cshtml:

      
      
      
      @RenderBody()
      
      
      
      
    3. Replace the contents of ~/Views/Shared/_Layout.cshtml with this:

      @{
          Layout = "~/Views/Shared/_LayoutBase.cshtml";
      }
      
      @section footerScripts{
          @RenderSection("footerScripts", false)
      }
      
      @RenderBody()
      
    4. Right click on the project and add an Admin area

    5. Add a TestController to this admin area and add a corresponding ~/Areas/Admin/Views/Test/Index.cshtml view:

      @{
          ViewBag.Title = "Index";
          Layout = "~/Views/Shared/_Layout.cshtml";
      }
      
      

      Index

      @section footerScripts{ alert('ok'); }
    6. Run the application and navigate to /admin/test/index
    7. The alert is shown

提交回复
热议问题