asp.net-mvc – 使用Ajax.Beginform的RedirectToAction,意外结果
发布时间:2020-05-28 15:50:55 所属栏目:asp.Net 来源:互联网
导读:我有以下视图,其中包含一个Ajax.BeginForm: – @using (Ajax.BeginForm(ChangeDevicesSwitch, Switch, new AjaxOptions{ InsertionMode = InsertionMode.InsertBefore, UpdateTargetId = result, LoadingElem
|
我有以下视图,其中包含一个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 – Chrome34忽略域名为“.cloudapp.net”的coo
- asp.net – 在SessionPageStatePersister中保持ViewState
- asp.net会员提供者Guid userID
- 为什么用户信息存储在ASP.NET的默认成员资格提供者的两个不
- IIS反向代理不使用ASP.NET中的Response.Redirect()
- 获得一个字符串的汉语拼音码
- asp.net – 屏幕读者测试网站的可访问性
- ASP.NET web.config:system.web.compilation中的debug属性
- asp.net – ASP MVC授权所有操作除了几个
- asp.net-mvc – jQuery Mobile和不显眼的验证
