Can I use Razor Views outside the 'Views' folder?

Hi Demis,

We keep all our application features code together as in the following example:

Is it possible to move the Razor Views - used by Services - into a new subfolder under their feature folder (e.g. wikis)?

Currently we are storing them in the root Views folder.


The short answer is “Yes, you can place your view pages any folder”. Basically any page that inherits from ViewPage is dynamically found, regardless of the folder its in within the project. There are some nuances, like name collisions & the virtual file system, but you’re not tied to the same strict layout as ASP.Net MVC.

1 Like

Please see the difference between Content Pages and View Pages in this question:

i.e. Any Razor View in /Views is treated as a View Page and is only rendered as the Response of a Service with the Response DTO used as the ViewModel in the Razor View page. Like @jklemmack says the Razor Views can be anywhere inside the /Views folder where it typically uses the same name as either the Request or Response DTO in order for them to get implicitly matched. Since Request DTO’s are unique there’s little chance for name collisions.

Any Razor View outside /Views is treated as a Content Page and can be accessed directly, i.e. doesn’t call a Service first.

Thanks. In my case I’m serving my pages from Services so I have to keep them in the Views folder.