C # MVC Core.Net 2.1 A Layout shared between different web projects in the same solution

1

In C # .Net Core 2.1 I currently have a solution composed of several web projects (MVC) and these must be managed in a common front, that is to say that you must navigate through the pages of the different projects from a single application. This is where my doubt arises, since I can not share a single layout between my different projects, this in order to have the same visual appearance for the whole application.

Try to create the layout in the web1 project and call it in the _ViewStar.cshtml file in the following way, but the system tells me that it is not able to find the layout file:

My _ViewStar.cshtml code of web project # 1 (source layout for all other projects):

@{
    Layout = "_Layout";
}

This first works and shows the design without problem in the application.

My _ViewStar.cshtml code for web project # 2

@{
    Layout = "~/NombreSolucion/ProyectoWeb2/Views/Shared/_Layout.cshtml";
}

The reason for having several web projects in the same solution is that the client requested it that way and I can not change this architecture.

What I'm looking for is not to repeat the code and the components of the layout in each of the web projects, since in the future any change would have to be replicated in each project.

Thank you very much.

    
asked by usrDeveloper 27.12.2018 в 21:38
source

2 answers

0

As of asp.net core 2.1 there are Razor libraries which can contain views, pages, drivers that can be reused by multiple web projects.

I did a quick test creating a library, referencing it in both projects and eliminating _Layout.cshtml of both also and it worked. You can follow the documentation to see how to create libraries of this type: link

    
answered by 27.12.2018 / 23:07
source
0

You need the .cshtml file physically in the project to be able to reference it, it occurs to me that you could define it in a project and then use the option Add as Link to add it in the other projects, then everyone will point to it

    
answered by 27.12.2018 в 21:51