简体   繁体   English

'RedirectToAction' 不重定向到给定的动作

[英]'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这是我的 RouteConfig 文件

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.先感谢您。

If you use AJAX call redirects don't work with an AJAX post.如果您使用 AJAX 调用重定向,则 AJAX 帖子将不起作用。 The browser will ignore a redirect response to an AJAX POST.浏览器将忽略对 AJAX POST 的重定向响应。 It's up to you to redirect in script if you need to redirect when an AJAX call returns a redirect response.如果您需要在 AJAX 调用返回重定向响应时重定向,则由您在脚本中重定向。

Your Code seems okay.你的代码看起来没问题。 It needs proper inspection now.它现在需要适当的检查。 Put breakpoint in AddPurchaseOrder and PurchaseOrderDetails actions.AddPurchaseOrderPurchaseOrderDetails操作中放置breakpoint Check why it hits your logout action, put a breakpoint on logout function.检查为什么它会触发您的注销操作,在注销功能上放置一个breakpoint May be your authentication checkup conditions violates or some bugs out there.可能是您的身份验证检查条件违反或存在一些错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM