How do you write your own View engine for ASP.NET MVC?
Asked Answered
Q

3

5

I know that ASP.NET MVC will allow me to swap in various View engines that other people have created, but I am wondering how can I create my own View engine?

More info: We have our own webforms based CMS and the main selling point about MVC is that it gives us cleaner HTML (which our designers would love). However we have a desire to create our own domain-specific View implementation.

Quarterback answered 27/12, 2008 at 12:36 Comment(0)
Q
5

OK, I did some Google-fu and found these posts:

Adding support for skins in an ASP.NET MVC application

Partial Rendering & View Engines in ASP.NET MVC

I think I can work it out from what these guys say - I just hope that it still applies in the latest ASP.NET MVC drop!

EDIT: There is also a nice post about using VB.NET XML literals for a view engine.

Quarterback answered 27/12, 2008 at 12:42 Comment(0)
S
3

It's too easy, here's what I did:

  1. Create a class derived from VirtualPathProviderViewEngine (in fact, you can just copy WebFormsViewEngine and edit it slightly).

  2. Create a class derived from IView. There's only one method - put your magic here.

  3. In Global.asax.cs:

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

Serai answered 6/2, 2009 at 20:26 Comment(0)
O
2

Check out http://mvccontrib.org/ for a couple samples of different ViewEngines. There are 4 included (well, minus one that's obsolete but the code is still available)

Oblation answered 29/1, 2009 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.