Where to grab controller / view resolution in ASP.Net MVC for settings?

I am trying to figure out where is the appropriate place to intercept the resolution of which view + controller is called in ASP.Net MVC 2. I have a situation where I have a controller and an appropriate set of views. I also have the ability to customize the controller version and N views sitting in the project (or we can use something like Portable Views from the MvcContrib project). If a custom version of the controller or views exists at runtime and the user meets certain criteria, I need to invoke a custom controller and use the appropriate customized view. At the time of design / compilation, we do not know what settings may be in place.

My first launch in this case was to use a factory user controller, which returns a user controller if one exists. However, this controller is โ€œconnectedโ€ to standard views, and I cannot figure out how to return a customized view if it also exists.

To complicate matters, there cannot be a customized controller, but customized views and vice versa.

+4
source share
1 answer

You seem to be on the right track. You have a user controller selection logic, but you also need to have a custom view selection logic.

You can override and extend the standard ViewEngine to connect to your application, which uses your own logic to find viewing locations. Here is a good walkthrough of a simple ViewEngine that does just that.

+2
source

Source: https://habr.com/ru/post/1312591/


All Articles