I would like to get the html code a view would generate in a string, modify it in my controller, then add it to my JsonResult.
I found code that would do what i'm talking about from a partial. I would like to do it from an aspx View though.
-- Extra explanation:
Let's say I have a page Frame.aspx that /Controller/Frame will return
I would like to get my hand on the response before it out so I can to wrap it with jsonp. I do not wish to edit the return result in code every time, this is why I want to load the view programmatically.
/Controller/Frame currently returns Frame.aspx's content: <html><body>hello</body></html>
Let's say there's a function that renders a view in a string builder
StringBuilder sb = new StringBuilder();
RenderView(sb, "Frame");
now take sb and wrap it with jsonp:
public JsonResult Frame(string callback)
{
StringBuilder sb = new StringBuilder();
RenderView(sb, "Frame");
return new JsonResult
{
Data = "(function() { " + callback + "(" + clientResponse + "); })();"
,
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}