I am trying to show a modal pop up by making a getjson call like this from my javascript:
$.getJSON('/Home/somefunction', function(result) {
var toto = $(result);
alert(toto);
});
public ActionResult somefunction()
{
return new JsonResult { Data = PartialView("modal pop up partial view") };
}
My modal pop up view is partialview.
- I don’t know if this is right way to convert partial view into jsonresult inside my controller function.
- I dont know, how to use the result in getjson to show was pop up(do I need to assign to any div)?
Thanks
The better way is to return a PartialView from the controller. Use
$.getor$.ajaxto make a GET request to the server (or a POST if you need), and the callback will have the HTML. You can then inject the HTML into the parent view (inside the modal).