In asp.net core mvc, I had multiple locations specified for the views. so, if view was missing in one location, it gets fetched from the other location.
I have a CMS with asp.net core mvc where controllers and views comes in a compiled library. If I don't want to use the view from the library, it's easy to add a new one e.g. /Views/ControllerName/Index.cshtml
and then the application will use this view instead of fetching from the library.
How can it be done in razor pages? Basically, I want to have an option to override the razor view of any page by adding a .cshtml file in a location.
Use an
IViewLocationExpander
, adding your custom location(s) before the default ones.Here's an example that would look into an "Override" folder:
Then register it in your
Startup
class: