Asp.net MVC Ajax form that return Json to a javascript method
ajax, asp.net-mvc, jquery
Solution
Try this (taken from How to use Ajax.BeginForm MVC helper with JSON result?):
<%using (Ajax.BeginForm("Form", "Controller", new AjaxOptions() { OnComplete = "MethodThatIWantToGetTheJson" }))
<script type='text/javascript'>
function MethodThatIWantToGetTheJson(content) {
alert(content.get_response().get_object());
}
</script>
Problem
I have an ajax form that saves a object in the database then return a Message like this: ``` return Json(new {Message = "Message!"}, JsonRequestBehavior.AllowGet); ``` We are ok here, but I don't know HOW I'll get this result in the view to display in a jQuery modal. My ajax form is like the following and I want to get the result on the OnSuccess method: ``` <%using (Ajax.BeginForm("Form", "Controller", new AjaxOptions() { OnSuccess = "MethodThatIWantToGetTheJson" }))%> ``` Any ideas?