Reputation: 9568
I have a ASP.NET MVC4 controller function that returns dynamic html using a StringBuilder as a Json result.
This is an quality issue, because I don't want dynamic HTML being returned as a string property in a JSON result.
My goal is to make use of ASP.NET MVC to use .cshtml for example with a viewmodel so that I make an instance of the viewmodel, passing in the results and in the end, return the raw HTML of the view as a JSON result.
How can this be achieved ?
Upvotes: 0
Views: 441
Reputation: 248
Instead of returning an HTML string inside of a JSON object, you may want to consider an action that returns a PartialView directly.
If you can't do this, because you need to return MULTIPLE html strings in one call, then I would advise taking a look at this thread which has a nice static method to turn a rendered view into a String: Render a view as a string.
Upvotes: 2