Take the 2-minute tour ×

Although I read dozens of answers I could not find a solution. I'm using MVC 3 with Razor. I have a simple Form with client validation via ajax. This part works fine. My problem is: In the update Action of my Controller I want to redirect to another Action. If the user disables Javacript, this works fine. But with javascript/ajax enabled, the redirectaction doesn't seem to work. Instead it looks like if some kind of partialview or something like that is executed.

My Controller/Action-code:

Function UpdateItem(Item As CItem) As ActionResult

  ' some validation code, save etc.

  if everythingok then
        Return RedirectToAction("Updatesuccess")
        Return RedirectToAction("EditItem")

End Function

My html page looks like (shortened/pseudo):

Logo image
some text


When the form is submitted via ajax the new html code is added beyond "some text", so the form is replaced but everything above the replaced form stays on the page. When ajax/javascript is disabled then after submit a whole new page is loaded. I checked the http headers and noticed, that with ajax there is no redirect (which is logical in some way because it is ajax). What can I do? I want to redirect to a new page.

Is it possible to disable the ajax-submit and only use the "normal" form-submit? I like the client validation via ajax while the user enters data and I want to use this, but for me it would be good enough, if the submit would be a "normal" submit.

I hope someone understands what I want and can help me.


share|improve this question

1 Answer 1

up vote 3 down vote accepted

I'm not a 100% sure I understand your question, but what the heck, don't downvote me :)

The problem is, redirect works via sending a HttpResponse with the redirect indicated in the headers, which the browser understands. If you submit via AJAX, it's not the browser that handles the request, it's your OWN JS code.

Here is the trick: instead of returning a redirect, return the Url (preferably as json), and then redirect manually using window.location. I'm not fluent in VB, here is how I'd do it in C#:

var url = new UrlHelper(this.ControllerContext.RequestContext);
var link = url.Action("UpdateSuccess");
return Json(new {link});

and then in jQuery:

    $.ajax({ method: 'POST',
             url: 'your post url', 
             success: function(result) {window.location = result.link; },
             // ... (passing form etc)
share|improve this answer
Thanks for your answer. Because I'm not that strong at js, it took me a while to make it run, but it's fine. –  Karl Hamann Mar 26 '12 at 14:02

Your Answer


