简体   繁体   中英

Using different layouts in an ASP.NET MVC3 project (Razor)

My ASP.NET MVC3 project consists on the one hand of the Website itself and on the other hand of something like an "Admin control panel". This means I have to use 2 completely different master layouts.

there are several ways to achieve this:

  • on top of each admin view, I could add @{ Layout = "~/.../_AdminLayout.cshtml"; }
  • I could also use the overloaded View-method in admin controllers, eg return View("Index", "_AdminLayout", viewModel);

But both approaches are a little bit in contrast with the DRY principle.

What is the most common approach? Is there perhaps a way to put some logic in the _ViewStart file that can automatically decide whether to use the admin or the normal page layout, if yes, how?

In the case it is helpful, my routings for both sections are different.

Normal page: {controller}/{action}/{id}
Admin page: admin/{controller}/{action}/{id}

如何创建管理区域并在_ViewStart文件中设置该区域的管理主布局?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM