Reputation: 31
I'm working on mvc.net and I want to create view pages at run time. Is it possible? If yes then how can I do it?
Upvotes: 2
Views: 877
Reputation: 10664
We actually store NVelocity snippets in a database that we pull together at runtime and marry with ViewData objects to get an output HTML string that we just return via Content() instead of View().
It boils down to something like this (pseudo-code, 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 ever touching Visual Studio or deploying anything at the filesystem level.
It didn't take too much to add things like MimeType handling etc. and we can have people outside of the development team editing the views.
Upvotes: 1