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

46 lines
1.6 KiB
Plaintext

@using Newtonsoft.Json;
@{
ViewData["Title"] = "UpdateTableware";
}
<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.Tablewares, "Id", "TablewareName"))"></select></div>
</div>
<div class="row">
<div class="col-4">Название прибора:</div>
<div class="col-8">
<input type="text" name="TablewareName" id="TablewareName" />
</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 selectedTablewareId = $(this).val();
var tablewares = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Tablewares));
var selectedTableware;
for (var i = 0; i < tablewares.length; i++) {
if (tablewares[i].Id == selectedTablewareId) {
selectedTableware = tablewares[i];
break;
}
}
console.log(selectedTableware);
if (selectedTableware) {
$('#TablewareName').val(selectedTableware.TablewareName);
}
});
$('#Id').val($('#Id option:first').val()).change();
});
</script>