1

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.

Hammad Sajid
  • 312
  • 1
  • 3
  • 14
Niharika
  • 71
  • 1
  • 9
  • Possible duplicate of [How do you redirect to a page using the POST verb?](https://stackoverflow.com/questions/129335/how-do-you-redirect-to-a-page-using-the-post-verb) – Marco Apr 30 '19 at 07:07
  • 1
    Please share the action method signature to which you are trying to redirect to. Also the code you are using to call this AddPurchaseOrder action – akg179 Apr 30 '19 at 07:58

2 Answers2

0

If you use AJAX call redirects don't work with an AJAX post. The browser will ignore a redirect response to an AJAX POST. It's up to you to redirect in script if you need to redirect when an AJAX call returns a redirect response.

hassan.ef
  • 1,300
  • 2
  • 11
  • 19
0

Your Code seems okay. It needs proper inspection now. Put breakpoint in AddPurchaseOrder and PurchaseOrderDetails actions. Check why it hits your logout action, put a breakpoint on logout function. May be your authentication checkup conditions violates or some bugs out there.

Shahjahan
  • 542
  • 5
  • 12