I'm using ASP.NET-MVC and returning JSON or HTML from my MVC actions.
I've come across some cases where I need to return BOTH JSON and HTML at the same time. For instance I may update a shopping cart and need to return an HTML representation as well as an updated JS object model.
I've found a lot of questions on SO about when to return which type of response, but none talking about how to return both.
Is there a reliable way of doing this? Must work across browsers without any extra thought.
- multi-part response?
- HTML encoded in the JSON result?
- some kind of script tag embedded in the HTML containing JSON that would run a function to update the object model. i'm leaning towards this method, but concerned that scripts may not reliably be run when adding them to the DOM with html("...")
- some other way?
If theres not a good way I'll just have to make 2 requests to get the HTML and then the JSON.