1

Why the Confirm view is not loaded after this successful ajax call? I can see the "success" alert, step into the controller action code (in debug mode) and see the correct id value.

        // send nonce and verification data to your server

        var nonce = payload.nonce;

          $.ajax({
            type: "POST",
            url: '/store/confirm/',
            data: { id: nonce },
            success: function(data) {
                alert('success');
            }
        });

Controller action successfully called:

public class StoreController : Controller
{
    public ActionResult Confirm(string id)
    {
        return View(); // this view never display on browser!
    }
}       
abenci
  • 8,422
  • 19
  • 69
  • 134

1 Answers1

1

Use following code:

public ActionResult Confirm()
{
   return View();
}

[HttpPost]
public ActionResult Confirm(string id)
{
    return Json(new { redirectToUrl = "/store/Confirm" });
}

Ajax:

$.ajax({
        type: "POST",
        url: '/store/confirm/',
        data: { id: nonce },
        success: function (response) {
            window.location.href = response.redirectToUrl;
        }
    });
Kris van der Mast
  • 16,343
  • 8
  • 39
  • 61
Yinqiu
  • 6,609
  • 1
  • 6
  • 14
  • Thanks. I get the following error: _JsonResult does not contain a constructor that takes 1 argument._ – abenci Jan 22 '21 at 07:07