Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC(3) handleUpdate

I am going through this tutorial on codeplex, which is the MusicStore application.

In a senario it is adding music records to the shopping basket. Then it also allows users to remove it. From my understanding it does it via an Ajax postback which is implemented in Controller.

The thing that puzzles me is that there are references of a JavaScript function called "handleUpdate()" which is declared on the same page. It seems to update the shopping basket after for example an item has been removed from the basket. I can not see it being called from anywhere. Could anyone please explain how and when it is called?

like image 645
daehaai Avatar asked Mar 09 '11 08:03

daehaai


1 Answers

It is not referenced in the code, but it is mentioned in the tutorial. Seems like a leftover to me.

Quote from http://www.asp.net/mvc/tutorials/mvc-music-store-part-8:

...instead of using an Html.ActionLink to remove items from the cart, we’ll use Ajax.ActionLink:

@Ajax.ActionLink("Remove from cart", "RemoveFromCart", 
new { id = item.RecordId }, new AjaxOptions { OnSuccess = "handleUpdate" })

This method works very similarly to the Html.ActionLink helper method, but instead of posting the form it just makes an AJAX callback to our RemoveFromCart. The RemoveFromCart returns a JSON serialized result, which is automatically passed to the JavaScript method specified in our AjaxOptions OnSuccess parameter – handleUpdate in this case. The handleUpdate Javascript function parses the JSON results and performs four quick updates to the page using jQuery:

  1. Removes the deleted album from the list
  2. Updates the cart count in the header
  3. Displays an update message to the user
  4. Updates the cart total price
like image 137
Daniel Liuzzi Avatar answered Nov 15 '22 11:11

Daniel Liuzzi