tags:

views:

11

answers:

1

I am trying to figure out where the appropriate place is to intercept the resolution of what view + controller is being called in ASP.Net MVC 2. I have a situation where I have a controller and a corresponding set of views. I also have the possibility of a customized version of both the controller and N of the views sitting in the project (or we may use something like Portable Views from the MvcContrib project). If the customized version of the controller or view(s) exists at run time, and the user satisfies certain criteria, I need to call the customized controller and use the appropriate customized view. At design/compile time we don't know what customizations may be in place.

My first run at this was by using a custom controller factory that returns a custom controller if it exists. However, this controller is "wired up" to the standard view, and I cannot figure out how to return the customized view if it also exists.

To complicate matters, there may be no customized controller but customized views, and visa-versa.

+1  A: 

Sounds like you're on the right track. You've got custom controller selection logic in place, but you need to also have custom View selection logic.

You can override and extend the default ViewEngine to plug into your app that uses your own logic to look for the view locations. Here's a good walkthrough of a simple ViewEngine that does exactly that.

womp
I ended up doing a fairly custom view discovery from a custom ViewEngine + the custom stuff I already had working in the ControllerFactory that went much further than this example, but it definitely got me on the right path. Thanks for the help.
Jason Jackson