How to specify a global MVC layout without specifying a layout path in razor mode

I am trying to get away from having to manually specify the layout path in every Razor view that I have / create.

So, in razor mode, you usually specify view / layout properties, such as:

@{
    ViewBag.Title = "About Us";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}

I have a basic controller that inherits all my controllers, in which I would like to specify the layout at this level or, alternatively, in app_start, etc.

For any exceptions, I would just override this in the view itself.

After an extensive search, I did not find any evidence that anyone else could do this.

My current, best workaround is to specify this in the ViewBag so that it is dynamic, but I still need to put the ad in the view:

@{
  Layout = ViewBag.Layout;
}

Is it possible? Solutions?

+4
2

: http://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts

MVC3 , ...

_ViewStart.cshtml( _ViewStart.vbhtml VB) \Views :

_ViewStart , . , _ViewStart.cshtml "" _ContentLayout.cshtml :

@{Layout = "~/Views/Shared/_ContentLayout.cshtml";}

, ( , ).

+3

Nkosi, , _ViewStart.

, , ...

  • _ViewStart ( ), .
  • _ViewStart View Area _ViewStart.

Specifying different layouts in each folder

+3

Source: https://habr.com/ru/post/1649868/


All Articles