asp.net-mvc – Ajax.BeginForm,调用操作,返回JSON,如何在我的OnSuccess JS函数中访问JSON对象?

Ajax.BeginForm调用一个动作然后返回JSON。
如何在我的OnComplete js函数中访问JSON对象?

所以我的Ajax.BeginForm看起来像这样…

using (Ajax.BeginForm("Coupon",new AjaxOptions { OnSuccess = "CouponSubmitted" }))

和我的OnSuccess功能看起来像这样…

function CouponSubmitted() {
    var data = response.get_response().get_object();
    alert(data.success);
}

我也试过…

function CouponSubmitted(data) {
    alert(data.success); 
}

我的控制器“Coupon”返回这个…

return Json(new { success = false,nameError = nameError,emailError = emailError });

关于如何访问Json的任何想法可以返回?

解决方法

function OnSuccess(e) { //function CouponSubmitted(data) in the question
   var json = e.get_response().get_object();
   alert(json.success);
}

这就是AJAX.BeginForm OnSuccess回调函数所希望的,可以让你的JSON返回。

希望通过记录下来的“功能”,我可以饶恕别人吗?

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...