views:

1387

answers:

2

Hi, I'd like to use two view engines in my asp.net mvc web application. The first one is the Brail view engine from MVCContrib project, and another one is my custom view engine for generating javascript code. However, I can't configure the application to use both engines. I'd like to use view file extension to discern which engine should handle the request - .brail for Brail engine - .json - for my custom engine

When I add two engines to the ViewEngines collection in global.asax.cs, the system is always looking for *.brail views and throws exception if it doesn't find one. It never looks for my *.json views... Is it a problem with the ASP.Net mvc framework, with Brail view engine or with my code? How should it be handled?

+1  A: 

I believe you can change your view engine in the controller. So I would extend your controller to select a view engine by extension.

Min
That isn't needed. The ViewEngines already tell the framework which extensions they can handle.
Craig Stuntz
Viewengines tell the framework which file extensions they handle in your own system. He isn't talking about the extension of the views, he's talking about changing the view engine depending on the extension of the request.
Min
+2  A: 

Like this.

EDIT: If your custom ViewEngine isn't handling *.json, you might well have a bug in your view engine. The easiest way to deal with this is to subtype VirtualPathProviderViewEngine and set the MasterLocationFormats, ViewLocationFormats, and PartialViewLocationFormats in the constructor. See the source code for WebFormViewEngine for a very simple example. This way the framework code does all the lifting for you.

Craig Stuntz