Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

brail - How to use multiple view engines in ASP.NET MVC application

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...