Share via


The layout page "~/Views/Shared/****.cshtml" could not be found at the following path:

Question

Friday, September 4, 2015 3:30 PM

I am fairly new to ASP.Net and MVC.  I know this is a subject that is mentioned a lot but I have not been able to resolve my issues with it.   I have a solution that includes 2 projects. Pro1 uses MVC4 and .Net Framework 4.  Proj2 use MVC3 and .Net Framework 4.  I am working with Window 7, using Visual Studio 2012 Update 4. Proj1 is used in several other solutions and works as intended, so I'm certain that nothing is wrong with that project.  Proj1 is referenced in Proj2.  Proj2 has been working fine until about a month ago when I decided to run the application to walk through some of it's functionality and it failed; references were dropped and when I replaced them it still failed giving the layout page could not be found error. No code changes have been made! 

The error references "~/Views/Shared/ContentOnlyPage.cshtml" which is in Proj1.  I have walked through the code and it flows like this:

         _ViewStart.cshtml in Proj2 calls @{Layout = "~/Views/Shared/_Layout.cshtml";} in Proj2

         _Layout.cshtml in **Proj2 **then calls @{Layout = "~/Views/Shared/ContentOnlyPage.cshtml"} in Proj1.  

In the _Layout.cshtml page in Proj2, I have walked through the code and fails at the @RenderBody()  The layout page "~/Views/Shared/ContentOnlyPage.cshtml" could not be found at the following path. Is there a reference that I could be missing or any other ideas as to what could be causing this?

Thanks in advance!
Chrys

* *

All replies (5)

Friday, September 4, 2015 3:59 PM ✅Answered

If Proj2 needs access to "~/Views/Shared/ContentOnlyPage.cshtml" you need to copy it to that project.

The tilde-slash "~/" means the path is relative to that specific application's root.


Tuesday, September 8, 2015 12:08 AM ✅Answered

Hello ChrysDW1,

Please see: http://stackoverflow.com/questions/24341336/mvc-views-located-in-another-project

As suggested "MVC does not compile views into DLL's, but instead references them as files from the root of your site directory.  The location, by convention is ~/Views and a search path is followed.  This is more or less hard coded into the default view engines." So to work around this you might need to create custom view engine.

But it is more trouble then worth. I would suggests that you keep the layouts in single projects.

With Regards,

Krunal Parekh


Saturday, September 5, 2015 5:46 AM

I think, it will not be possible. 


Saturday, September 5, 2015 7:50 AM

_Layout.cshtml in Proj2 then calls @{Layout = "~/Views/Shared/ContentOnlyPage.cshtml"} in Proj1.

Your using the layout page from another project.  I am not sure you can do that. 

Copy ContentOnlyPage.cshtml from Proj1 to Proj2 and it will work. 

Anyway i found this blog

http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html

Regards


Saturday, September 5, 2015 3:04 PM

try using the full path eg c:/x/y/z/proj/views/_layout.cshtml