This project is read-only.

View search sequence problem?

Jun 6, 2013 at 1:55 PM
Edited Jun 6, 2013 at 2:02 PM
After I’ve put all my views - except ~/views/shared/_layout.cshtml - of my mvc application in to a separate assembly the view ~/Area/Admin/Home/Index.cshtml of my area is not rendered anymore? Instead, when I call the Home controller of the Admin area mvc renders the precompiled ~/Home/shared/Index.cshtml. Any idea what went wrong?
How does razorgenerator influence the view search sequence?
AndyK
Jun 6, 2013 at 5:46 PM
You can order the engines however way you want in the App_Start code, which may help here.
Jun 6, 2013 at 5:58 PM
Could you verify
a) if the assembly the RazorGeneratorMvcStart is pointing to is the right one - in this case the separate assembly?
b) The PageVirtualPath in the generated views point to the right location? For example, open up <AreaProject>\Areas\Admin\Views\Home\Index.cs and check if the path is correct? If you simply moved those files over from the old project, it is likely that the paths weren't updated to match this. You can run "Redo-RazorGenerator" from the package manager console to redo all the files in your new assembly at once.
Jun 6, 2013 at 8:38 PM
Edited Jun 6, 2013 at 8:39 PM
davidebbo: How can I do this? The initialization is controlled by the webactivator attributes in razorGeneratorMvcStart.cs and other ?
Jun 6, 2013 at 8:50 PM
Edited Jun 7, 2013 at 7:50 AM
pranavkm: everything looks fine. I think the problem is related to the _layout.cshtml. The projects main Views folder has only one containing folder “Shared” with _layout.cshtml in it. And it has a _viewstart.cshtml in folder “Views” which is pointing to _layout.cshtml in the “Shared” folder. My area also has a “Shared” folder with its own _layout.chtml in it, and again its own _viewstart.cshtml in the “Views” folder, pointing to ~/Area/Admin/View/Shared/_layout.cshtml in the area.
But a runtime the _layout.cshtml of the main Folder ~/Views/Shared/ is used instead of ~/Area/Admin/View/Shared/_layout.cshtml?
Jun 7, 2013 at 1:19 AM
You can choose whether you add your PrecompiledMvcEngine at the beginning (Insert(0)) or at the end, which can influence what is picked. I would think that if the precompiled engine is first, then _layout should come from there.
Jun 7, 2013 at 10:08 AM
Edited Jun 7, 2013 at 2:07 PM
Adding the PrecompiledMvcEngine at the end fixed the problem. Thanks!
But I am a little scared. Maybe this dependency will cause other problems somewhere else....
I have created a minimalistic test project that reproduces this issue. If you are interested please let me know and I will send it to you.
Jun 7, 2013 at 3:12 PM
GitHub is the easiest way to share repros.

This thread is somewhat related, though dealing with multiple PrecompiledMvcEngines. Maybe the best solution would be to have a single engine here as well that wraps a PrecompiledMvcEngine and the regular one, but I don't know how easy that is to write such thing.
Jun 7, 2013 at 7:25 PM
Get it here https://github.com/Avareto/Repro/tree/master/RazorGenerator
Let me know what you found out.
Jun 10, 2013 at 6:13 AM
Your project seems broken (missing package restore?). But in any case, I think it's clear that there is some trickiness when the same view paths exist both in precompiled assemblies and in non-precompiled form. Though in many cases, re-ordering the engines ends up solving the problem.