I use ASP.NET-MVC and return JSON or HTML from my MVC actions.
I came across some cases where I need to return BOTH JSON and HTML at the same time. For example, I can update the shopping cart and you need to return the HTML view as well as the updated JS object model.
I found a lot of questions about when to return an answer such as an answer, but no one talks about how to return both.
Is there a reliable way to do this? It should work in browsers without any extra thoughts.
- multi-part answer?
- JSON encoded HTML?
- A script tag embedded in HTML containing JSON that runs a function to update the object model. I am inclined to this method, but I am worried that scripts can be reliably launched when adding them to the DOM using html ("...")
- in any other way?
If this is not the case, I just need to make 2 requests to get HTML and then JSON.
source share