Question

How to use certain view engine for certain controller?

Now my project using MVC2 + Spark view engine. I want to migrate to Razor view engine. Project so big, and I want to do this step-by-step.

Was it helpful?

Solution

It's perfectly possible to run both view engines simultaneously. Since you're currently using Spark you probably have an entry in your global.asax that clears the current view engines and adds in the Spark engine. Something like:

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new ...);

MVC is designed to use FindView and FindPartial (part of the ViewEngine interface) to find the correct view for an action, and if it can't find one for the first view engine in the list, it moves on to the next viewengine and looks for its appropriate views, until there aren't any other view engines to try.

It's up to you whether it looks for Razor Views first and then falls back to Spark, or the other way round, so make sure you place the ViewEngines in the correct order. Or to have the default engines, you can delete the ViewEngines.EnginesClear() line and make Spark first by using ViewEngines.Engines.Insert(0, ...)

If that's not clear then paste in the global.asax code around the Spark bit and I can try to help you more.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top