How to set same layout from different areas in MVC 6 Vnext,
I am using _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"
I think this is your scenario:
\Areas
folderTo do this 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.cshtml
you can have the following:
@{
Layout = "_Layout1";
}
This will make all views in all areas use \Views\Shared\_Layout1.cshtml
.
NOTE: You can NOT put _ViewStart.cshtml
in the following locations:
\Views\_ViewStart.cshtml
\Views\Shared\_ViewStart.cshtml
NOTE: You CAN put _ViewStart.cshtml
in the following location:
\Areas\Home\_ViewStart.cshtml
NOTE: This also applies to _ViewImports.cshtml
I'm only discarting the obvious things... Did you tried with ...? (I only have viewed a few of things about VNext )
Layout = "~/Views/Shared/_Layout.cshtml";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With