I want to pass data from <input>
value and corresponding recordID to controller method for each cart item in my shopping cart.
My for loop generate input field for each cart item like this
<table>
@for (int i = 0; i < Model.CartItems.Count; i++)
{
<tr>
<td>
<input data-id="@Model.CartItems[i].RecordID" type="text" value="@Model.CartItems[i].CartCount"/>
</td>
</tr>
}
<tr>
<td>
<button class="UpdateQuantity">Save Changes</button>
</td>
</tr>
</table>
This is my try hard script.I don't know how to get that data-id and value of input so i can pass both to controller method. I want to send pair of id and input value for each cart item in shopping cart so method can update quantity changes for every product in cart.
$(".UpdateQuantity").click(function(){
$("input[data-id][value]").each(function(i){
$.ajax({
type:"POST",
url:"/ShopingCart/UpdateCartQuantity",
data:{"id":input[data-id],"cartCount":input[value]},
dataType:'json',
cache:false,
contenttype:"application/jsonrequest; charset=utf-8"
}
)
})})