Returning a JSON view in combination with a boolean
Posted
by Rody van Sambeek
on Stack Overflow
See other posts from Stack Overflow
or by Rody van Sambeek
Published on 2010-04-13T08:57:30Z
Indexed on
2010/04/13
10:22 UTC
Read the original article
Hit count: 346
What i would like to accomplish is that a partiel view contains a form. This form is posted using JQuery $.post. After a successfull post javascript picks up the result and uses JQuery's html() method to fill a container with the result.
However now I don't want to return the Partial View, but a JSON object containing that partial view and some other object (Success -> bool in this case).
I tried it with the following code:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, Item item)
{
if (ModelState.IsValid)
{
try
{
// ...
return Json(new
{
Success = true,
PartialView = PartialView("Edit", item)
});
}
catch(Exception ex)
{
// ...
}
}
return Json(new
{
Success = false,
PartialView = PartialView("Edit", item)
});
}
However I don't get the HTML in this JSON object and can't use html() to show the result. I tried using this method to render the partial as Html and send that. However this fails on the RenderControl(tw) method with a: The method or operation is not implemented.
© Stack Overflow or respective owner