views:

42

answers:

2

Is there a way to include some aspx/ascx markup in a DLL and use that to generate text dynamically? I really just want to pass a model instance to a view and get the produced html as a string. Similar to what you might do with an XSLT transform, except the transform input is a CLR object rather than an XML document. A second benefit is using the ASP.NET code-behind markup which is known by most team members.

One way to achieve this would be to load the MVC view engine in-process and perhaps have it use an ASPX file from a resource. It seems like I could call into just the ViewEngine somehow and have it generate a ViewEngineResult. I don't know ASP.NET MVC well enough though to know what calls to make.

I don't think this would be possible with classic ASP or ASP.NET as the control model is so tied to the page model, which doesn't exist in this case.

Using something like SparkViewEngine in isolation would be cool too, though not as useful since other team members wouldn't know the syntax. At that point I might as well use XSLT (yes I am looking for a clever way to avoid XSLT).

+1  A: 

You can host ASP.NET Runtime in another application. See :- http://msdn.microsoft.com/en-us/magazine/cc188791.aspx

Also see http://www.west-wind.com/presentations/aspnetruntime/aspnetruntime.asp

Hightechrider
Thanks, though I'm looking for a lighter approach. If I where to host the whole runtime, in this case I'd just run IIS itself and make requests to localhost. More robust for the scenario I'm looking at.
Frank Schwieterman
BTW: You can avoid the request/response cycle in either scenario: See http://stackoverflow.com/questions/1403167/how-to-email-screen-in-asp-net-mvc/2249319#2249319
Hightechrider
Thats what I was looking for, thanks.
Frank Schwieterman
A: 

You could take a look at SharpDOM view engine - http://sharpdom.codeplex.com/ - probably it could help

vtimashkov