首页 > 解决方案 > '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.

标签: c#asp.net-mvcasp.net-mvc-4

解决方案


如果您使用 AJAX 呼叫重定向,则不适用于 AJAX 帖子。浏览器将忽略对 AJAX POST 的重定向响应。如果在 AJAX 调用返回重定向响应时需要重定向,则由您在脚本中重定向。


推荐阅读