ASP.NET MVC. How to return json with html
I have a controller method (Method1) that should return JsonResult with the following properties:
return Json(new { someProperty1开发者_StackOverflow = 'value1', someProperty2 = 'value2', html = "html_code_that_will_be_rendered" });
As you can see it has 'html' property. This html should be generated as a result (HTML) of another controller method (Method2). The question is how can I get a rendered HTML code of Method2 in Method1 of the controller?
If you mean, how can you pass the html variable as say:
<p>Some actual html</p>
and then output it on method1, you would need to assign the result of the call to method2 to something you can access, eg. myHtml and then use the HTML.Raw() function like this:
@Html.Raw(myHtml)
This will avoid the Razor view engine encoding all your html
精彩评论