c# - How to make an Ajax Post Back with ASP.net MVC -
i new mvc . , have been studying code of musicstore application in codeplex.
i unable understand following code meant:
// 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 albumname = storedb.carts .single(item => item.recordid == id).album.title; // remove cart int itemcount = cart.removefromcart(id); // display confirmation message var results = new shoppingcartremoveviewmodel { message = server.htmlencode(albumname) + " has been removed shopping cart.", carttotal = cart.gettotal(), cartcount = cart.getcount(), itemcount = itemcount, deleteid = id }; return json(results); } // // get: /shoppingcart/cartsummary [childactiononly] public actionresult cartsummary() { var cart = shoppingcart.getcart(this.httpcontext); viewdata["cartcount"] = cart.getcount(); return partialview("cartsummary"); } } }
please me clarify , how particluar httppost works ajax post .
hi can use jquery ajax make asynchronous postback request
please see code below
$.ajax({ type: "post", url: @url.action("removefromcart"), data: ({ id:1 }), success: success, datatype: datatype })
[httppost] -- attribute ensures removefromcart action method accepts post requests
[childactiononly] -- attribute ensures action method can called child method within view. these typically associated partial views.
Comments
Post a Comment