c# - 'RedirectToAction' not redirect to given action
问题描述
I perform an operation of the insert and move my control to a detail page. but it did not redirect to a detail page and direct gives me login page.
Here is my code
[HttpPost]
public ActionResult AddPurchaseOrder(PODetail po)
{
var createdby = GeneralSession.Username;
var spresult = Db.Sp_PO_Insert(po.SCODE, po.PONO, po.PODATE, po.POTYPEID, po.MODESP, po.INSURANCE, po.PTERM, po.DESTINATION, po.PackingCharge, po.NOTE1, po.NOTE2, po.NOTE3, po.NOTE4, po.INSPECTION, po.FRAIGHT, po.SALESTYPE, po.PRICEARE, po.OtherAmt, po.OtherDesc, createdby, po.Remarks);
if (spresult == 2 || spresult == -2)
{
if (po.SubPODetails.Count() > 0)
{
var src = po.SubPODetails.ToList();
for (var i = 0; i < po.SubPODetails.Count(); i++)
{
var fdata = src[i];
var poli = i + 1;
var subresult = Db.Sp_POSub_Insert(po.PONO, fdata.ITEMCODE, fdata.DESCRIPTION, fdata.QTY, fdata.UNITID, fdata.RATE, fdata.DISCOUNT, fdata.DELIVERYDT, fdata.SpecialNote, fdata.QTNNO, fdata.QTNDT, fdata.CGSTPer, fdata.IGSTPer, Convert.ToString(poli));
if (subresult == 1 || subresult == -1)
{
continue;
}
else
{
this.AddToastMessage("Error", "Something went wrong in insert with sub OA", ToastType.Error);
break;
}
}
}
else
{
this.AddToastMessage("Error", "Something Went To Wrong!!!", ToastType.Error);
}
ModelState.Clear();
this.AddToastMessage("Success", "Purchase inserted successfully", ToastType.Success);
return RedirectToAction("PurchaseOrderDetails","Purchase");
}
else
{
this.AddToastMessage("Error", "Something Went To Wrong!!!", ToastType.Error);
}
return RedirectToAction("PurchaseOrderDetails", "Purchase");
}
And Here is my RouteConfig file
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "User", action = "Login", id = UrlParameter.Optional }
);
}
}
can anyone please help me why toast message not alert and page not redirect to a given action. Thank You in advance.
解决方案
如果您使用 AJAX 呼叫重定向,则不适用于 AJAX 帖子。浏览器将忽略对 AJAX POST 的重定向响应。如果在 AJAX 调用返回重定向响应时需要重定向,则由您在脚本中重定向。
推荐阅读
- angular - 元标记在我的角度应用程序中没有更新
- amazon-web-services - dynamodb ttl 属性和 RCU
- python - 如何从代码中的 bs4 标签元素中提取文本?使用内容功能不起作用
- python - 如何将 Plotly 图保存在 ipynb 文件中?
- julia - Julia 中对称类型的意义何在?
- python - Python 套接字服务器无法解码来自 OAUTH 的重定向
- r - 如何为R中的约束输入一系列值
- html - 为什么我的 `flex` 表格行不在 Edge 中居中?
- linux - 无法为 Beaglebone AI 配置 5GHz WiFi 频段
- python - python>=3.5 由诗歌管理的项目下如何使用python black formatter?