2011-02-18 63 views
6

我在我的控制器之一中使用了下面的代码;asp.net mvc ajax post - redirecttoaction不起作用

  if (Request.IsAjaxRequest()) { 
      return RedirectToAction("PreviewAndSendEmail"); 
     } 

我调试它,它来到返回线,但重定向没有发生。是否有可能在Ajax.BeginForm中做到这一点?这里是剃刀代码;

using(Ajax.BeginForm(new AjaxOptions { LoadingElementId = "loading" })) { 

    <b>Choose E-mail Template : </b>@Html.DropDownList("emailtemps")<br /><br /> 

    <input type="submit" value="Preview & Send" /> 

    <span id="loading" style="display: none;"> 
     <img title="loading..." alt="load" src="@Url.Content("~/Content/App_Icons/gifs/loading.gif")" 
    </span> 

} 
+0

可能重复http://stackoverflow.com/questions/3534956/how-can-i-redirecttoaction-within-ajax-callback – 2011-02-18 13:36:50

回答

15

您不能在服务器的AJAX操作中重定向。如果你想让你的浏览器在AJAX动作中重定向,你需要使用javascript。显然使用AJAX重定向是绝对没用的。如果你打算重定向使用一个正常的Html.Begin形式,并不打扰与AJAX。

+1

感谢您的评论。我同意你的这个观点。我用它来显示加载gif。有没有其他方式显示gif – tugberk 2011-02-18 14:29:40

1

为什么不直接调用PreviewAndSendMailEmail?由于您不需要重定向本身(更改网址等),因此无需使用它。