Asp.net mvc ajax post - redirecttoaction not working

In one of my controllers, I used the following code:

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

I debugged it and it returned to the return line, but no redirection occurred. Is it possible to do this inside Ajax.BeginForm? Here is the razor code,

  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> } 
+6
ajax asp.net-mvc asp.net-mvc-ajax
source share
2 answers

You cannot redirect AJAX action from the server. If you want your browser to be redirected to AJAX action, you need to do it from javascript. Obviously using AJAX for redirection is completely useless. If you intend to redirect using the regular Html.Begin form and don’t worry about AJAX.

+15
source share

Why don't you call PreviewAndSendMailEmail directly? Since you do not need a redirect (changing the URL, etc.), there is no need to use it.

+1
source share

All Articles