Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SiMonChit opened this issue Nov 23, 2023 · 2 comments
Open

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

SiMonChit opened this issue Nov 23, 2023 · 2 comments

Comments

@SiMonChit
Copy link

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.

@KavinTony01
Copy link

Since you are not pushing any values to the TempData["returnURL"], you are getting null reference exception.

You can use
return RedirectToAction("Index", "MyCart");

@alienware-net
Copy link

Can you help me how to connect the db with the project or how to get started with the project. I didn't know R49_MyEcommerceDB file and MyEcommerceDbContext is the same? I have restored R49_MyEcommerceDB in sql server; add new model of data with R49_MyEcommerceDB in visual studio but can't not run. It has the error like this

System.Data.Entity.ModelConfiguration.ModelValidationException: 'One or more validation errors were detected during model generation:

MyEcommerceAdmin.Models.admin_Employee: : EntityType 'admin_Employee' has no key defined. Define the key for this EntityType.
MyEcommerceAdmin.Models.admin_Login: : EntityType 'admin_Login' has no key defined. Define the key for this EntityType.
MyEcommerceAdmin.Models.genPromoRight: : EntityType 'genPromoRight' has no key defined. Define the key for this EntityType.
MyEcommerceAdmin.Models.OrderDetail: : EntityType 'OrderDetail' has no key defined. Define the key for this EntityType.
MyEcommerceAdmin.Models.RecentlyView: : EntityType 'RecentlyView' has no key defined. Define the key for this EntityType.
MyEcommerceAdmin.Models.PaymentType: : EntityType 'PaymentType' has no key defined. Define the key for this EntityType.
MyEcommerceAdmin.Models.ShippingDetail: : EntityType 'ShippingDetail' has no key defined. Define the key for this EntityType.
MyEcommerceAdmin.Models.genMainSlider: : EntityType 'genMainSlider' has no key defined. Define the key for this EntityType.
admin_Employee: EntityType: EntitySet 'admin_Employee' is based on type 'admin_Employee' that has no keys defined.
admin_Login: EntityType: EntitySet 'admin_Login' is based on type 'admin_Login' that has no keys defined.
genPromoRights: EntityType: EntitySet 'genPromoRights' is based on type 'genPromoRight' that has no keys defined.
OrderDetails: EntityType: EntitySet 'OrderDetails' is based on type 'OrderDetail' that has no keys defined.
RecentlyViews: EntityType: EntitySet 'RecentlyViews' is based on type 'RecentlyView' that has no keys defined.
PaymentTypes: EntityType: EntitySet 'PaymentTypes' is based on type 'PaymentType' that has no keys defined.
ShippingDetails: EntityType: EntitySet 'ShippingDetails' is based on type 'ShippingDetail' that has no keys defined.
genMainSliders: EntityType: EntitySet 'genMainSliders' is based on type 'genMainSlider' that has no keys defined.
'

image
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants