PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenVisitorApp/Views/Home/UpdateOrder.cshtml
2023-06-19 19:11:35 +03:00

45 lines
1.5 KiB
Plaintext

@using Newtonsoft.Json;
@{
ViewData["Title"] = "UpdateOrder";
}
<header>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</header>
<div class="text-center">
<h2 class="display-4">Данные заказа</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Заказ:</div>
<div class="col-8"><select id="Id" name="Id" class="form-control" asp-items="@(new SelectList(@ViewBag.Orders, "Id", "Id"))"></select></div>
</div>
<div class="row">
<div class="col-4">Пожелания:</div>
<div class="col-8">
<input type="text" name="description" id="description" />
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div>
</form>
<script>
$(document).ready(function () {
$('#Id').change(function () {
var selectedOrderId = $(this).val();
var orders = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Orders));
var selectedOrder;
for (var i = 0; i < orders.length; i++) {
if (orders[i].Id == selectedOrderId) {
selectedOrder = orders[i];
break;
}
}
if (selectedOrder) {
$('#description').val(selectedOrder.Description);
}
});
$('#Id').val($('#Id option:first').val()).change();
});
</script>