So i have a list of orders. Every order/row have i checkbox. The checkbox represents id the order is ready for delivery or not. So i wanna trigger an event in my jquery every time i click and change a rows checkbox. So My code below works fine only on the top row. The rest of the rows dont get triggerd.
I put an breakpoint write below the "$("#readyForShipping").on("change", function () {" line to se the event gets triggerd. And the breakpoint again only gets activated when i click att the first rows checkbox. Why, i dont know and need help with. But iam pretty sure the problem is that the rest of the rows dont get triggerd for some reason.
So iam trying to get to my actionmethod "finishedForDelivery()" in my controller with the parameters of
my html + jquery:
@model OrderViewModel
<html xmlns="http://ift.tt/lH0Osb">
<head>
<title></title>
</head>
<body>
<html xmlns="http://ift.tt/lH0Osb">
<head>
<title></title>
</head>
<body>
<br />
<div class="row top-buffer col-xs-pull-12">
<table style="width:100%">
<tr>
<th>Order Numer</th>
<th>Klar för leverans</th>
<th>Produkt namn</th>
<th>Leveransdatum</th>
<th>Pris</th>
<th>code</th>
</tr>
@foreach (var order in Model.orderList)
{
<tr>
<td><input type="number" readonly id="orderNr" name="orderNr" value="@order.Id" /></td>
<td><input type="checkbox" name="readyForShipping" id="readyForShipping" checked="@order.IsFinishedForDelivery" /> </td>
<td><input type="text" readonly id="productName" name="productName" value="@Model.getProductName(order.ProductID)" /></td>
<td><input type="datetime" value="@order.DeliveryDate" readonly /></td>
<td><input type="number" readonly value="@order.TotalPrice" /></td>
<td><input type="text" value="@order.Code" /></td>
</tr>
}
</table>
</div>
</body>
</html>
</body>
</html>
@section scripts{
<script type="text/javascript">
$(document).ready(function () {
$("#readyForShipping").on("change", function () {
//console.log($("#percent-of-price").val().toString())
var id = $(this).closest("tr").find('#orderNr').val();
var fin = $(this).closest("tr").find("#readyForShipping").is(':checked').toString()
$.ajax({
type: "POST",
url: '@Url.Action("finishedForDelivery", "Account")',
data: "isFiniedForDelivery=" + fin + "&orderId="+ id,
success: function () {
location.reload();
}
});
});
});
</script>
}
my controller:
public class AccountController: Controller
{
[Authorize(Roles = "Admin")]
public ActionResult AdminPage()
{
OrderViewModel model = new OrderViewModel(_context);
model.orderList = Repository.OrderRepository.getAllOrders(_context);
return View(model);
}
[Authorize(Roles = "Admin")]
public void finishedForDelivery(string orderId, bool isFiniedForDelivery)
{
Repository.OrderRepository.finishedForDelivery(orderId, isFiniedForDelivery, _context);
}
}
Aucun commentaire:
Enregistrer un commentaire