c# - Javascript remove from cart is not refreshing properly -
the view not refreshing when doing remove cart. item has been remove screen still showing product name, price , quantity. expecting line reomved totally. trying mvc music store platine.com remove there seems not working (http://asp-net-mvc.platine.com/shoppingcart# )
can explain me why not refreshing ? can't find part missing here. thanks
here output looks like:
details of cart: checkout >> ----------- baseball glove has been removed shopping cart. product price(unit) quantity baseball glove 44.99 1 remove cart <== line should remove ? -------------- ---------------- <== line should remove ? total 0 <== line should remove
index.cshtml
@model tp1webstore3.viewmodels.shoppingcartviewmodel @{ viewbag.title = "shopping cart"; } <script src="/scripts/jquery-1.8.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('.removelink').click(function () { $.ajax({ url: '/panier/removefromcart', data: { id: $(this).data('id') }, type: 'post', cache: false, success: function (result) { $('#row-' + result.deleteid).fadeout('slow'); $('#cart-status').text('cart (' + result.cartcount + ')'); $('#update-message').text(result.message); $('#cart-total').text(result.carttotal); }, error: function(xmlhttprequest, textstatus, errorthrown) { alert("status: " + textstatus); alert("error: " + errorthrown); }); return false; }); }); </script> <h3> <em>details</em> du panier: </h3> <p class="button"> @html.actionlink("checkout >>", "addressandpayment", "checkout") </p> <div id="update-message"> </div> <table> <tr> <th> produit </th> <th> prix (unitaire) </th> <th> quantite </th> <th></th> </tr> @foreach (var item in model.cartitems) { <tr id="row-@item.produitid"> <td> @html.actionlink(item.produit.description,"details", "produit", new { id = item.produitid }, null) </td> <td> @item.produit.prix </td> <td id="item-count-@item.panierid"> @item.quantite </td> <td> <a href="#" class="removelink" data-id="@item.panierid"> enlever du panier </a> </td> </tr> } <tr> <td> total </td> <td></td> <td></td> <td id="cart-total"> @model.carttotal </td> </tr> </table>
paniercontroller.cs
// ajax: /shoppingcart/removefromcart/5 [httppost] public actionresult removefromcart(int id) { // remove item cart var cart = shoppingcart.getcart(this.httpcontext); // name of album display confirmation string produitdescription = dbproduit.paniers .single(item => item.panierid == id).produit.description; // remove cart int itemcount = cart.removefromcart(id); // display confirmation message var results = new shoppingcartremoveviewmodel { message = server.htmlencode(produitdescription) + " has been removed shopping cart.", carttotal = cart.gettotal(), cartcount = cart.getcount(), itemcount = itemcount, deleteid = id }; return json(results); }
shoppingcartremoveviewmodel.cs
using system; using system.collections.generic; using system.linq; using system.web; namespace tp1webstore3.viewmodels { public class shoppingcartremoveviewmodel { public string message { get; set; } public decimal carttotal { get; set; } public int cartcount { get; set; } public int itemcount { get; set; } public int deleteid { get; set; } } }
here google pf12 network removefromcart. means javascript ran think. preview
{message:baseball glove has been removed shopping cart., carttotal:0, cartcount:0,..} cartcount: 0 carttotal: 0 deleteid: 131 itemcount: 0 message: "baseball glove has been removed shopping cart."
response
{"message":"baseball glove has been removed shopping cart.","carttotal":0,"cartcount":0,"itemcount":0,"deleteid":131}
Comments
Post a Comment