asp.net mvc的阿贾克斯后 - redirecttoaction不工作 [英] asp.net mvc ajax post - redirecttoaction not working
问题描述
我用下面的code在我的控制器中的一个;
如果(Request.IsAjaxRequest()){
返回RedirectToAction(previewAndSendEmail);
}
我调试它,它涉及到回线,但重定向并没有出现。是否有可能做到这一点里面Ajax.BeginForm?这里是剃须刀code;
使用(Ajax.BeginForm(新AjaxOptions {LoadingElementId =加载})){
< B>选择电子邮件模板:LT; / B> @ Html.DropDownList(emailtemps)< BR />< BR />
<输入类型=提交值=preVIEW和放大器;发送/>
<跨度ID =装的风格=显示:无;>
< IMG标题=载入中...ALT =加载SRC =@ Url.Content(〜/内容/ App_Icons / GIF动画/ loading.gif)
< / SPAN>
}
您不能重定向来自服务器的AJAX动作。如果你希望你的浏览器中的AJAX操作重定向,你需要从JavaScript做到这一点。显然,使用AJAX来重定向是绝对没有用的。如果你打算使用重定向正常Html.Begin形式,不与AJAX麻烦了。
I used the following code in one of my controller;
if (Request.IsAjaxRequest()) {
return RedirectToAction("PreviewAndSendEmail");
}
I debugged it and it comes to return line and but redirect didn't occur. Is it possible to do that 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>
}
You can't redirect in an AJAX action from the server. If you want your browser to redirect in an AJAX action you need to do it from javascript. Obviously using AJAX to redirect is absolutely useless. If you intend to redirect use a normal Html.Begin form and don't bother with AJAX.
这篇关于asp.net mvc的阿贾克斯后 - redirecttoaction不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!