MVC3 Custom view engine

Posted by eth0 on Stack Overflow See other posts from Stack Overflow or by eth0
Published on 2011-11-16T09:59:59Z Indexed on 2011/11/21 9:50 UTC
Read the original article Hit count: 154

Filed under:
|
|
|

I have a custom View Engine that derives from WebFormViewEngine. There's a lot of stuff going on in here, mostly caching. I want to be able to use WebFormViewEngine AND RazorViewEngine at the same time, is this possible? Ideally I'd like to do;

ViewEngines.Add(new MyViewEngine<WebFormsViewEngine>()); ViewEngines.Add(new MyViewEngine<RazorViewEngine>());

if a .ascx/.aspx/.master file exists then use WebForms, otherwise use Razor is a .cshtml file exists.

EDIT: I should of worded my question better. As my custom view engine derives from WebFormViewEngine it obviously uses WebForms, I can't derive from two classes. I can derive from RazorViewEngine but then I'll loose WebForms. I can duplicate my code entirely, derive from RazorViewEngine and edit the views file extensions, etc. but as I said I've got a lot of custom code in my view engine and would be duplicating hundreds of lines.

WebFormViewEngine and RazorViewEngine derive from BuildManagerViewEngine which in turn implements IViewEngine. The problem with that is I have to implement methods CreatePartialView() and CreateView() but how would I know what to return (WebForms/Razor?) using generics?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc-3