asp.net-mvc – 使用Ajax.Beginform的RedirectToAction,意外结果
发布时间:2020-12-16 04:17:08 所属栏目:asp.Net 来源:网络整理
导读:我有以下视图,其中包含一个Ajax.BeginForm: – @using (Ajax.BeginForm("ChangeDevicesSwitch","Switch",new AjaxOptions{ InsertionMode = InsertionMode.InsertBefore,UpdateTargetId = "result",LoadingElementId = "progress2",HttpMethod= "POST",OnSu
我有以下视图,其中包含一个Ajax.BeginForm: –
@using (Ajax.BeginForm("ChangeDevicesSwitch","Switch",new AjaxOptions { InsertionMode = InsertionMode.InsertBefore,UpdateTargetId = "result",LoadingElementId = "progress2",HttpMethod= "POST",OnSuccess = "createsuccess",OnFailure = "createfail" })) //code goes here <p><img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress2" /></p> <div id ="result"></div> 以及将从Ajax.Bginform调用的以下Action方法: – public ActionResult ChangeDevicesSwitch(SwitchJoin s) {//code goes here try { var count = repository.changeDeviceSwitch(s.Switch.SwitchID,(Int32)s.GeneralSwitchTo,User.Identity.Name.Substring(User.Identity.Name.IndexOf("") + 1)); repository.Save(); return RedirectToAction("Details",new { id = s.GeneralSwitchTo }); } catch (Exception e) { return Json(new { IsSuccess = "custome",description = "Error occurred. Please check...." },JsonRequestBehavior.AllowGet); } } 将在Ajax.BeginForm返回成功时运行的脚本是: – function createsuccess(data) { if (data.IsSuccess == "Unauthorized") { jAlert(data.description,'Unauthorized Access'); } else if (data.IsSuccess == "False") { jAlert('Error Occurred. ' + data.description,'Error'); } else if (data.IsSuccess == "custome") { alert(data.description); } else { jAlert('Record added Successfully ','Creation Confirmation'); } } 目前我遇到的一个问题是,当RedirectToAction到达时,整个视图将显示在当前视图内!如果返回RedirecttoAction,有没有办法强制我的应用程序不更新目标? 解决方法
操作成功时,返回要从操作方法重定向的URL:
public ActionResult ChangeDevicesSwitch(SwitchJoin s) { try { ... return Json(new { RedirectUrl = Url.Action("Details",new { id = s.GeneralSwitchTo }) }); } ... } 并在创建成功: function createsuccess(data) { if (data.RedirectUrl) window.location.href = data.RedirectUrl; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-2 – 将复杂对象从View传递给Controller:一个
- asp.net – 由TaskScheduler和SynchronizationContext混淆同
- asp.net – 命名空间“Microsoft”错误中不存在类型或命名空
- asp.net-mvc – ASP.NET MVC:自定义排序
- asp.net-mvc – 在ASP.NEt MVC 3中传递Html.BeginForm()中D
- asp.net-mvc – 在Azure中启用自定义错误
- asp.net-mvc – 如何从ASP MVC5中的属性路由获取路由名称
- asp.net – 带超时异常的reCaptcha验证
- asp.net-mvc – 如何从umbraco mvc中的表面控制器添加查询字
- 如何在aspx页面中隐藏ASP.NET自定义控件的属性?
推荐文章
站长推荐
- ASP.Net WCF服务的Thread.CurrentPrincipal被联邦
- asp.net – Webservices可以作为单身人士引起不同
- ASP.Net Forms身份验证在10分钟后注销用户
- asp.net-mvc-2 – 什么是MapRoute名称空间参数?
- 在控件asp.net之间动态添加
- asp.net-mvc – ASP.NET MVC依赖注入Unity与WCF服
- asp.net-mvc – 将DataTable从控制器传递到Parti
- asp.net – 我的通用ActionLink在哪里?
- asp.net – WebForm_DoCallback定义
- asp.net – 如何从System.Web.HttpPostedFileBas
热点阅读