Custom view not being picked up.

Dec 20, 2011 at 10:08 AM

I am in the process of upgrading my application to the latest  Naked Objects MVC version.

Created a brand new MVC project and merging my changes into it.

I decided to this time leave the generic views on aspx, and to only use Razor for my custom views, as recommended in the manual.

However, while, for example, the generic aspx standalone view exists, my custom view is not being picked up. When I rename the generic aspx file, then it works correctly. The generic cshtml view is also still there, but does not prevent my custom view from being picked up.

Coordinator
Dec 20, 2011 at 10:22 AM

I am struggling to follow ... can you show all the actual filenames  you are talking about (and their relevant directories), in both the non-working and working cases?

 

Dec 20, 2011 at 11:28 AM
Generic views
\Views\Shared\StandaloneTable.aspx
\Views\Shared\StandaloneTable.cshtml

My custom view:
\Views\Message\StandaloneTable.cshtml

If the files exist like the above, it does not resolve to my custom view.
If I delete or rename StandaloneTable.aspx, then it resolves to my custom view.
Dec 20, 2011 at 11:33 AM

This is a known behaviour according to the documentation: "To use Razor views throughout, simply delete (or rename) all the .aspx files."

Coordinator
Dec 20, 2011 at 11:48 AM

The behaviour you are describing is generic to ASP.NET MVC, not specific to Naked Objects.

Dec 20, 2011 at 1:29 PM
Edited Dec 20, 2011 at 1:31 PM

>This is a known behaviour according to the documentation: "To use Razor views throughout, simply delete (or rename) all the .aspx files.

Yes, when I want it to use the generic StandaloneTable.cshtml in stead of StandaloneTable.aspx, not when I want it to use the custom view in stead of the generic view. Or so I thought.

>The behaviour you are describing is generic to ASP.NET MVC, not specific to Naked Objects.

I am then confused by the meaning of the following section in the manual, because this is what prompted me to use generic aspx views, with custom cshtml views.

"When retrieving a named view, ASP.NET MVC3 will look first for a .aspx file of that name, and if none is found will look for a .cshtml file of the same name. It is therefore possible to combine the use of both viewing engines in one project: for example you might choose to use the default .aspx views for generic presentation, but write any custom views to the Razor conventions."

And the reason for using aspx generic views in the first place:

"The Razor translations of the generic views are provided as a convenience to developers. They have not been subject to the same testing as the .aspx views and might contain errors. If using these translations, please test for correct functioning. Remember that you can always switch back to .aspx views selectively if problems are encountered. Please report any errors found in the Razor views via the Naked Objects forum."

Coordinator
Dec 20, 2011 at 2:36 PM

Fair point.  I'm not sure what I was trying to say when I wrote that para.  I'll remove it because it is clearly misleading.  View selection is done by the MVC framework, not by Naked Objects.

Dec 20, 2011 at 2:42 PM

Ok. Just thought I was missing something.

I'll stick with all Razor then.