Render ASP.NET MVC view from a string -
This may be a bad idea for any reason, but I still want to complete it. Is to any way to present some HTML and code blocks in a string? My initial idea is that I will implement IView
and have to put the HTML string in the constructor. Next, with the model, pass it in the view
method, such as:
Public Functionality MyAction () {var str = @ "& lt; html> Lt; body & gt; & lt;% = model. Some properties are%> gt; & lt; / body & gt; & lt; / html & gt; "; Var myView = new MyIView (str); See Return (myView, Model); }
At this point I am having some difficulty because I do not know how to implement the view engine to parse the string and do all this work. Or, at this time, do I have to parse and present myself? Unfortunately, it's not easy to do for ASPX pages.
In it, it is very easy.
If you really want to do this, register a custom Virtual PacePower
which resolves a particular path, call your strings, then BuildManager. Call CreateInstanceFromVirtualPath
, enter it in ViewPage
, set its ViewData , and call
RenderView
.
Comments
Post a Comment