I have a custom view engine developed internally. In the same project, I would like to use Razor for some pages and my custom engine for some pages. How does MVC framework choose which engine to use? BTW, my custom engine does not require any templates, it renders pages based on meta-data from database. For my custom engine I don’t want to setup any template files.
What I am expecting is there should be a way to drive framework to use certain engine based on the controller name and action name.
Is this flexibility exists in MVC3?
I have a custom view engine developed internally. In the same project, I would
Share
Your view engine should implement the IViewEngine interface. After you registered your view engine with the
ViewEngines.Engines.Add()method, the MVC framework will call FindView and FindPartialView whenever it needs a view engine to render a view.It’s absolutely possible for multiple view engines to operate side by side. If you don’t want your view engine to be used in a specific situation you
return new ViewEngineResult(new string[0]);fromFindVieworFindPartialViewand MVC will choose another view engine. If you do want your view engine to be used you return a valid ViewEngineResult pointing to the view class (that is implementing IView) that you want to Render the result.There are some specifics with the
useCacheparameter. If you want to know more, there was an excellent presentation on building your own view engine at TechEd 2011 by Louis DeJardin. You can find the video of Writing an ASP.NET MVC View Engine at Channel9.