3

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?

4

2 回答 2

3

像这样。

编辑:如果您的自定义 ViewEngine 没有处理 *.json,那么您的视图引擎中很可能有错误。处理此问题的最简单方法是子类型 VirtualPathProviderViewEngine 并在构造函数中设置 MasterLocationFormats、ViewLocationFormats 和 PartialViewLocationFormats。请参阅 WebFormViewEngine 的源代码以获取一个非常简单的示例。这样,框架代码就可以为您完成所有工作。

于 2008-12-11T14:19:40.717 回答
2

我相信您可以在控制器中更改视图引擎。因此,我将扩展您的控制器以通过扩展选择视图引擎。

于 2008-12-10T19:57:06.323 回答