MVC 6 VNext How to set the same layout from different areas

How to set the same layout from different areas in MVC 6 Vnext,

I use _ViewImports.cshmlt and _ViewStart.cshtml in each area

in _ViewStart.cshtml

@{
    Layout = "_/Views/Shared/_Layout.cshtml";
}

and _ViewImports.cshtml

@using Cross2Enterprise.Administrador
@using Cross2Enterprise.Administrador.Models
@using Microsoft.Framework.OptionsModel
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
+4
source share
2 answers

I just refuse the obvious things ... Have you tried with ...? (I just looked at a few things about VNext)

Layout = "~/Views/Shared/_Layout.cshtml"; 
+4
source

I think this is your scenario:

  • ASP.NET Core w / MVC
  • Using Folder \Areas
  • You want to set the template used by all areas in one place.

To do this, you must have the following project layout:

\Areas\Home
\Areas\Home\Controllers
\Areas\Home\Views
\Areas\_ViewStart.cshtml
\Views
\Views\Shared\
\Views\Shared\_Layout1.cshtml
\Views\Shared\_Layout2.cshtml

Then in the file \Areas\_ViewStart.cshtmlyou can get the following:

@{
    Layout = "_Layout1";
}

\Views\Shared\_Layout1.cshtml.

. _ViewStart.cshtml :

\Views\_ViewStart.cshtml
\Views\Shared\_ViewStart.cshtml

. _ViewStart.cshtml :

\Areas\Home\_ViewStart.cshtml

. _ViewImports.cshtml

+6

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


All Articles