Ajax.BeginForm, Calls Action, Returns JSON, How do I access JSON object in my OnSuccess JS Function?

Viewed 31653

Ajax.BeginForm calls an action and then returns JSON. How do I access JSON object in my OnComplete js function?

so my Ajax.BeginForm looks like this...

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

and my OnSuccess function looks like this...

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

I also tried...

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

My controller "Coupon" returns this...

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

Any ideas on how to access the Json that gets returned?

4 Answers
Related