Can views be overridden?

Jun 20, 2013 at 9:48 PM
I'm starting to get my feet wet with the Razor Generator project. So far it looks very promising for what I need it to do, but I'm having an issue with overridden views.

Let's say I have a Class library/DLL which has the following compiled views:

Views\Home\A
Views\Home\B


...and in my main web project I have:
Views\Home\B
Views\Home\C



(for testing this, I'm starting with MvcApplicationRazorGeneratorSeparateLibrary project from https://github.com/davidebbo/MvcApplicationRazorGeneratorSeparateLibrary)

When I go to /Home/A, I go to the "A" view in the DLL, and when I go to /Home/C, I go to the "C" view in the main web site. So far so good.

When I go to Home/B, I go to the "B" view which is in the DLL, which is not what I want. If a view exists in the main web project, I want that version to be displayed, so I'd like the /Home/B view in my main project to be displayed.

Is this possible?

Thanks,

Jeff
Coordinator
Jun 20, 2013 at 10:26 PM
Mvc looks up views in the order view engines are registered. RazorGenerator.Mvc registers itself as the first view engine to use via App_Start. Change it to appear later in the list and this should sort it out for you.
Jun 21, 2013 at 3:08 AM
Thanks! That was perfect and just what I needed.

I changed the line in RazorGeneratorMvcStart.cs to:
        ViewEngines.Engines.Insert(ViewEngines.Engines.Count, engine);
(just in case anyone needs to know this in the future)

Thanks,

Jeff
Coordinator
Jun 21, 2013 at 7:17 AM
You can just use Add instead of Insert to put it at the end.