Create view pages at runtime
1 answer
We actually store NVelocity chunks in the database, which we put together at runtime and marry ViewData objects to get the HTML output string, which we simply return via Content () instead of View ().
It boils down to something like this (pseudocode, not actual code):
var _viewDataObject = Products.All();
var _view = PageTemplate.Single(template=>template.Slug == PageTemplateEnums.HomePage);
var _outputHtml = nvelocityMemoryEngine.Transform(_view,_viewDataObject);
return Content(_outputHtml);
While we do some caching for performance reasons, this means you can change views without affecting Visual Studio or deploying anything at the file system level.
There wasn't too much to add things like handling MimeType, etc., and we can get people outside of the dev team to edit views.
+1
a source to share