Trying to understand HttpPost in MVC3 [closed]?

Up vote 2 down vote favorite share g+ share fb share tw.

Possible Duplicate: MVC(3) handleUpdate I'm (slowly) learning how to use MVC 3 and at the moment I'm having a looking at the MvcMusicStore tutorial app on the asp.net website. Right now I'm trying to understand how HttpPost works. From what I can gather, the user performs whatever actions they want in their browser and then with the use of jQuery, the data is posted back to the server (to the corresponding function with HttpPost attribute) and then in this case, a json result is sent back to the browser which handles this and updates elements accordingly.

I understand this fine, but in the particular snippet of code I'm looking at, I can't understand how the 'handleUpdate()' function is being hit when there appear to be no calls made from either the js or the server-side code. Is there something I'm missing here? Anyway here is the front-end: @model MvcMusicStore.ViewModels.

ShoppingCartViewModel @{ ViewBag. Title = "Shopping Cart"; } Review your cart: @Html. ActionLink("Checkout >>", "AddressAndPayment", "Checkout") Album Name Price (each) Quantity @foreach (var item in Model.

CartItems) { @Html. ActionLink(item.Album. Title, "Details", "Store", new { id = item.

AlbumId }, null) @item.Album. Price @item. Count Remove from cart } Total @Model.

CartTotal and here is the (relevant) server-side code: // // AJAX: /ShoppingCart/RemoveFromCart/5 HttpPost public ActionResult RemoveFromCart(int id) { // Remove the item from the cart var cart = ShoppingCart. GetCart(this. HttpContext); // Get the name of the album to display confirmation string albumName = storeDB.

Carts . Single(item => item. RecordId == id).Album.

Title; // Remove from cart int itemCount = cart. RemoveFromCart(id); // Display the confirmation message var results = new ShoppingCartRemoveViewModel { Message = Server. HtmlEncode(albumName) + " has been removed from your shopping cart.

", CartTotal = cart.GetTotal(), CartCount = cart.GetCount(), ItemCount = itemCount, DeleteId = id }; return Json(results); } I can see that the handleUpdate() manipulates the DOM based on the returned JSON, but I can't figure out for the life of me how it's being called? Is there some jQuery magic going on or have I completely misunderstood how this all works? Thanks!

C# jquery asp.net asp.net-mvc-3 link|improve this question asked Feb 28 at 16:23alimac83976 72% accept rate.

1 It looks like someone else had the same question. To summarize, it looks like it is leftover from MVC2. I would verify that the script in that method is actually being hit.

– Ek0nomik Feb 28 at 16:26 Have you tried searching your source code for "handleUpdate"? – Jakub Konecki Feb 28 at 16:26 1 I don't see handleUpdate() being called either. I have to conclude that, in the code above, it is not being called.

– MrBoJangles Feb 28 at 16:28 Yea I searched the code for it and couldn't find any references - that's what I found odd! And thanks Ek0nomik - i'll take a look EDIT: Just read the link Ek0nomik - thanks, that's exactly what I was looking for! :) If you make a response to this thread I'll happily mark it as the answer.. – alimac83 Feb 28 at 16:28.

It's not being called. The relevant code on the client side that calls the RemoveFromCart method on the server side is this: if (recordToDelete! = '') { // Perform the ajax post $.

Post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete }, function (data) { // Handle result. }); } Note the URL is /ShoppingCart/RemoveFromCart, which maps to the URL route for the RemoveFromCart method. The jQuery post method is being used to make the call to the method on the controller, and then a closure (indicated by the function() { ... }) is passed, not the handleUpdate method.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions