MVC(3) handleUpdate

前端 未结 2 1186
小鲜肉
小鲜肉 2021-01-18 17:19

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 allo

2条回答
  •  野的像风
    2021-01-18 17:58

    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

提交回复
热议问题