Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible with ASP.NET MVC to render a view from a template pulled from a database?

What I'm trying to do is generate email content using different templates.

I think ASP.NET MVC could be a good fit for this. My controller would get the necessary data for the email and decide which view (template) to render. (It's more that just a simple mail-merge, there would need to be conditional blocks, foreach's, etc.)

I want to be able to store these templates in a database rather than as files in the web application, so new templates can be easily added from the web application itself.

Is this possible? I would prefer to be able to use the WebForms view engine, but would consider other view engines if that's not possible. I would ideally like to use typed views.

like image 588
John Rutherford Avatar asked Sep 23 '09 20:09

John Rutherford


1 Answers

Unfortunately, the WebForms ViewEngine uses some internal classes to compile the aspx and ascx files, so this is not possible. That ViewEngine requires that the Views are available as files in a folder inside the site's root (virtual folder will also work IIRC).

There are other ViewEngines that may fit your purpose better, including some that use XSLT.

AFAIR it is possible to mix several ViewEngines in the same application, so you could use the WebForms engine for your normal web pages, and a different one for your emails.

like image 183
Mark Seemann Avatar answered Sep 30 '22 17:09

Mark Seemann