Skip to content

AddToCart return Redirect(TempData["returnURL"].ToString()); #3

@SiMonChit

Description

@SiMonChit

In Product1Controller
I get the error so How to fixed and why this error
Can you explain me sir.

public ActionResult AddToCart(int id)
{
OrderDetail OD = new OrderDetail();
OD.ProductID = id;
int Qty = 1;
decimal price = db.Products.Find(id).UnitPrice;
OD.Quantity = Qty;
OD.UnitPrice = price;
OD.TotalAmount = Qty * price;
OD.Product = db.Products.Find(id);

        if (TempShpData.items == null)
        {
            TempShpData.items = new List<OrderDetail>();
        }
        TempShpData.items.Add(OD);
        AddRecentViewProduct(id);
        return Redirect(TempData["returnURL"].ToString());

    }

System.NullReferenceException: 'Object reference not set to an instance of an object.'

System.Web.Mvc.TempDataDictionary.this[string].get returned null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions