I am using asp.net mvc 2.0 to implement shopping cart application.My situation is , I have a order page, there i am adding the products to the Cart.Below it will show the Cart total.Next i will go to the shopping cart page to delete or editing the items.In this page it will show the same cart total as in the Order page.
But once again if i go back to the Order page to order some more products to the cart,the cart total in the order page is showing 0 amount. This is my Shopping cart controller action method,
public ActionResult ShoppingCart(int eventID) { Event e = eRepository.GetEvent(eventID); var cart = Stalbans.Models.ShoppingCart.GetCart(this.HttpC开发者_JAVA技巧ontext);
// Set up our ViewModel
var viewModel = new ShoppingCartViewModel { CartItems = cart.GetCartItems(), CartTotal = cart.GetTotal() }; TempData["data"] = cart.GetTotal(); if (viewModel.CartItems.Count != 0) { List listp = pRepository.GetProductsForEvent(e.EventID); foreach (string item in listp) { ViewData[item] = pRepository.GetProductsWithProdNameAndEventID(e.EventID, item); ViewData["sizelist"] = listp; Group g = new GroupRepository().GetGroup(new EventRepository().GetEvent(e.EventID).GroupID); ViewData["group"] = g; }
if(Request.IsAuthenticated) ViewData["returnUrlAfterLogOff"] = HttpContext.Request.RawUrl; ViewData["EventOrders"] = oRepository.GetOrderedEvents(User.Identity.Name); ViewData["eventModel"] = e;
return View(viewModel);
So once i will go to the shopping cart page from the order page and again coming back to the order page it has to show the same cart total. Actually data is persisted in the cart total but it is not showing .Because if you add one more item its amount will added to the existimng cart total and then shows the current cart total. So for the first time i click back at that it has to show the already existed cart total in the cart total value. So what is the best approach to do this .I have to use session state or somewhat please tell me.
Thanks in advance,
You might need to store the shopping cart into the session so that products added there are being persisted between page redirects.
精彩评论