如何使用多个视图引擎在ASP.NET MVC应用程序 [英] How to use multiple view engines in ASP.NET MVC application

查看:222
本文介绍了如何使用多个视图引擎在ASP.NET MVC应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的asp.net MVC Web应用程序使用两个视图引擎。
第一个是从MVCContrib项目抄网视图引擎,另一个是用于生成JavaScript code我的自定义视图引擎。
但是,我不能配置为使用两个引擎中的应用。我想使用查看文件扩展名来辨别哪些引擎应该处理请求
- .brail的抄网引擎
- 以.json - 为我定制的引擎

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

当我添加两个引擎的ViewEngines集合中的global.asax.cs,该系统一直在寻找* .brail意见,并抛出异常,如果没有找到一个。它从不寻找我的*以.json的看法...
它是与ASP.Net MVC框架的问题,与抄网视图引擎或与我code?应如何处理?

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?

推荐答案

筛选。

编辑:如果您的自定义视图引擎不处理*以.json,你可能会在你的视图引擎的错误。对付这种情况的最简单方法是亚型VirtualPathProviderViewEngine并在构造函数设置MasterLocationFormats,ViewLocationFormats和PartialViewLocationFormats。看到源$ C ​​$ C为WebFormViewEngine一个非常简单的例子。这样的框架code做所有的为您解除。

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.

这篇关于如何使用多个视图引擎在ASP.NET MVC应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆