Can a View be returned as a JSON object in ASP.Net MVC
- by Chev
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.