Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reference a Master view in a different project in ASP.NET MVC?

I'm creating an ASP.NET MVC solution, and inside I had 2 MVC Website projects.

I'm interested in creating a 3rd project called "Shared", where I can reference the shared views/content between the two sites so I have only one place to edit them.

  • WebUI.Site1 (ASP.NET MVC Site)
  • WebUI.Site2 (ASP.NET MVC Site)
  • WebUI.Shared (Newly created ASP.NET MVC Site)

How can I reference a Masterview's location if it is in a different project?

So, normally at the top of a view I would reference a Masterview like so:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Tabbed.Master" Inherits="System.Web.Mvc.ViewPage<WebUI.ViewModels.Admin.EditProfileViewModel>" %>

However,

Now, that "Tabbed.Master" isn't in the local project, it is in a difference project in the solution. I've created a reference to the project but I don't know how to reference Tabbed.Master from WebUI.Site1 to WebUI.Shared?

Something like:

<%@ Page Title="" Language="C#" MasterPageFile="WebUI.Shared.Views.Tabbed.Master" Inherits="System.Web.Mvc.ViewPage<WebUI.ViewModels.Admin.EditProfileViewModel>" %>

Doesn't work.

How can I reference the location of things like masterviews, css files, images across projects like that?

like image 494
KingNestor Avatar asked Nov 14 '22 15:11

KingNestor


1 Answers

Due to the nature of MasterViews, you need to find a filebased solution. The virtual path is one way to do it, but I think you will get in trouble at some point: How do you handle the file references when you use the internal Visual Studio web server?

And think of the pain you suffer when this virtual path is missing in IIS.

Visual Studio let you link to files from other projects. Those files will be copied over at compile time:

Right-click in Solution Explorer -> Add existing item... -> select files -> Add As Link

Personally, I don't care for this feature. But it seems to do what you need.

like image 69
Thomas Eyde Avatar answered Dec 19 '22 04:12

Thomas Eyde