Ajax redirection on ASP.NET MVC

Asked

Viewed 652 times

0

I’m using Ajax to save the form data. The problem is that after saving the data have no way redirect to the "Action Index" where customers are listed registered, because the request was made in Ajax. I thought to create a Partialview for this and render it with jQuery, but it would be redundant because there is already a View for this, which is the home of the system, as I said. Is there any other alternative to this?

1 answer

2


Redirect to ajax success:

    $.ajax({
        url: minhaurl,
        data: $("#meuform").serialize(),
        type: 'post',
        success: function (data) {
                window.location.href = "@Url.Action("Index", "Home")";

        }
    });

With this you guarantee that you only send if you receive a 200 from the server.

  • Thanks Ricardo! I only changed to window.location.href = ". /Home/Index", because that way you put Javascript did not recognize that it was C#.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.