0

I have two ASP.NET MVC 4 websites in a Visual Studio Solution.

I have a custom EditorTemplate in one of the websites and I want to reuse the same template in the other website. I tried to add this template as a link from the first website.

But when I launch the second website, my custom editor template is not rendered. When I open the template, I cannot even set a breakpoint there, it seems, Visual Studio does not see this template as part of the current MVC project.

As soon as I remove the linked template and add a copy of the actual template file, the template starts working.

Does it mean that for some weird reason ASP.NET MVC projects do not support linked cshtml files from another projects? Or maybe I am doing something wrong?

AstroCB
  • 12,337
  • 20
  • 57
  • 73
JustAMartin
  • 13,165
  • 18
  • 99
  • 183

1 Answers1

3

Does it mean that for some weird reason ASP.NET MVC projects do not support linked cshtml files from another projects?

Yes, that's exactly what it means. Views need to be physically located inside the same ASP.NET project. If you don't want this default behavior you will have to write a custom view engine which could allow you to locate views from anywhere. For example here's an article which illustrates how you could embed Razor views inside a reusable library and use them across various projects.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • The article itself is out-dated but there documentation on http://razorgenerator.codeplex.com/ on how to achieve this. – Dejan Jul 30 '14 at 05:15