我在一个ASP.NET MVC项目上工作。我面临的问题是,尽管没有错误发生,但操作ApprovalIndex
没有重定向到操作PendingManagersRequests
。
我调试和跟踪断点,直到达到动作PendingManagersRequests
,并跟踪,直到我达到查看return View(vmr);
没有任何问题。
那么,为什么没有重定向到视图PendingManagersRequests
,尽管没有问题发生?
我的代码:当单击按钮approve submit时,它会根据RequestNo
更新表列SpeakStuffComment
:
using (Html.BeginForm("ApprovalIndex", "Resignation", new { id = Model.RequestNo }, FormMethod.Post, htmlAttributes: new { @style = "display:inline;" }))
{
@Html.AntiForgeryToken()
<a onclick="submit();" class="btn btn-primary" style="min-width: 100px;
margin-left: 5px;">
<i class="glyphicon glyphicon-ok"></i> Approve
</a>
}
字符串
当单击approve按钮时,它会调用控制器ResignationController
上的ApprovalIndex
:
public class ResignationController : Controller
{
[HttpPost]
public async Task<ActionResult> ApprovalIndex(ResignationRequester REQ)
{
string errorMsg = string.Empty;
string requestStatus;
Workforce.ResignationUpdateLineManangerApproval(id, true,Convert.ToInt32(Session[SessionKeys.UserCode]));
return RedirectToAction("PendingManagersRequests", new { msg = $"Request NO {REQ.RequestNo} has been accepted " +
$"successfully." });
}
}
型
jQuery在resignation
控制器上调用action approvalIndex
:
function submit() {
var ResignationRequester = new Object();
ResignationRequester.RequestNo = document.getElementById("RequestNo").innerHTML.trim();
ResignationRequester.EmpID = document.getElementById("EmpID").innerHTML.trim();
ResignationRequester.SpeakStuffComment = document.getElementById("SpeakStuffComment").value;
if (ResignationRequester != null) {
$.ajax({
type: "POST",
url: '@Url.Action("ApprovalIndex", "Resignation")',
data: JSON.stringify(ResignationRequester),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
console.log(response);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
}
}
</script>
public async Task<ActionResult> PendingManagersRequests(string msg, string errorMsg)
{
ViewModelRequests vmr = new ViewModelRequests();
vmr.MyRequests = Workforce.GetPendingToDisplayMyRequests(Session[SessionKeys.UserCode].ToString());
ViewBag.msg = msg;
ViewBag.errorMsg = errorMsg;
return View(vmr);
}
型
最后,我只得到这个弹出本地主机说,虽然从行动approvalindex
没有错误
的数据
1条答案
按热度按时间x3naxklr1#
当你通过匿名调用服务器时,重定向不起作用。
你必须“重定向”(这不是真正的重定向)客户端:
字符串