Can a View be returned as a JSON object in ASP.Net MVC

Posted by Chev on Stack Overflow See other posts from Stack Overflow or by Chev
Published on 2010-04-10T11:17:40Z Indexed on 2010/04/10 11:23 UTC
Read the original article Hit count: 344

Filed under:
|

I want to know if it is possibe to return a view as a JSON object. In my controller I want to do something like the following:

        [AcceptVerbs("Post")]
        public JsonResult SomeActionMethod()
        {
            return new JsonResult { Data = new { success = true, view = PartialView("MyPartialView") } };
        }

In html:

 $.post($(this).attr('action'), $(this).serialize(), function(Data) {
                        alert(Data.success);
                        $("#test").replaceWith(Data.view);

                    });

Any feedback greatly appreciated.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about jQuery