jquery - Ajax update return a view or just demical? -


i have shopping cart summary table view:

<tbody>             @foreach (var line in model.cart.lines)             {                 <tr>                      <td>@line.product.name                     </td>                     <td style="text-align: center; padding: 0">@html.dropdownlist("quantity", new selectlist(viewbag.items system.collections.ilist, "value", "text", line.quantity), new { data = line.product.productid, @class = "quantity" })</td>                     <td>@string.format("{0:00,0 vnĐ}", line.product.price)</td>                     <td>@string.format("{0:00,0 vnĐ}", (line.quantity * line.product.price))</td>                     <td style="text-align:left"><a href="@url.action("removefromcart","cart",new{proid= line.product.productid, returnurl= request.url.pathandquery})"><img src="@url.content("~/content/images/delete.png")" style="padding-right:10px" /></a></td>                 </tr>             }          </tbody> 

i want when user change quantity dropdownlist, subtotal update.

here ajax jquery code:

function updatevalue() { $(document.body).on("change", ".quantity", function () {     var proid = $(this).attr("data");     var quatity = $(this).val();     $.ajax({         type: "get", url: "/cart/updatevalue",         data: { proid: proid, quantity: quatity },         success: function (data) {             $(".cart_box").html(data);         }     }         );     $.ajaxsetup({         cache: false     }); }); 

}

and controller:

 public partialviewresult updatevalue(cart cart,int proid, int quantity)     {         list<selectlistitem> items = new list<selectlistitem>();         (int = 1; <= 10; i++)         {             items.add(new selectlistitem { text = i.tostring(), value = i.tostring() });         }         viewbag.items = items;         product product = repository.products.firstordefault(p => p.productid == proid);         if (product != null)         {             cart.updateitem(product, quantity);         }         cartindexviewmodel ptview = new cartindexviewmodel { cart = cart, returnurl = "/" };         return partialview(ptview);     } 

the problem when add second product cart, if change dropdown value, it's changing first dropdown. , think ajax uptate return partial view not best method, return subtotal updated value. please show me best method , problem?


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -