我有一个ajax表单,在数据库中保存一个对象,然后返回一个这样的消息: return Json(new {Message = "Message!"}, JsonRequestBehavior.AllowGet); 我们在这里很好,但我不知道我将如何在视图中获得此结果以
return Json(new {Message = "Message!"}, JsonRequestBehavior.AllowGet);
我们在这里很好,但我不知道我将如何在视图中获得此结果以在jQuery模式中显示.我的ajax表单如下所示,我想在OnSuccess方法上得到结果:
<%using (Ajax.BeginForm("Form", "Controller", new AjaxOptions() { OnSuccess = "MethodThatIWantToGetTheJson" }))%>
有任何想法吗?
试试这个(取自 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>