This may be a bad idea for any number of reasons, but I still want to accomplish it. Is there a way to render a view from a string that contains some HTML and code blocks? My initial thought is that I would implement IView
and have that take the HTML string in the constructor. Then pass it to the View
method along with the model, like so:
public ActionResult MyAction() {
var str = @"<html><body><%= Model.SomeProperty %></body></html>";
var myView = new MyIView(str);
return View(myView, Model);
}
At this point I get a little stuck since I don't know how to invoke the view engine to parse the string and make it all work. Or, at this point, do I have to parse and render it myself?