Ajax提交重定向MVC 3

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")
  else
        Return RedirectToAction("EditItem")
  endif

End Function

My html page looks like (shortened/pseudo):

Logo image
H1
some text

<form>....</form>

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.

Thanks.

查看全部
weixin_33749242
weixin_33749242
2012/03/25 18:45
  • redirect
  • submit
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信

1个回复