ASP MVC View Content as JSON

Posted by Craig on Stack Overflow See other posts from Stack Overflow or by Craig
Published on 2009-05-26T00:15:34Z Indexed on 2010/04/30 7:57 UTC
Read the original article Hit count: 404

Filed under:
|
|

I have a MVC app with quite a few Controller Actions that are called using Ajax (jQuery) and return partial views content which updates a part of the screen. But what I would rather do is return JSON something like this.

return Json(new { 
    Result = true, 
    Message = "Item has been saved", 
    Content = View("Partial") 
});

Where the HTML is just a property of the Json. What this means is I need to retrieve the HTML that is rendered by the View method. Is there any easy way to do this, a few examples I have seen are quite convoluted.

Edit: This question was originally for ASP.NET MVC 1, but if version 2 makes it easier I would like to hear the answer.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about JSON