PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenManagerApp/Views/Home/CookUpdate.cshtml

48 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

2023-05-18 01:40:11 +04:00
@using Newtonsoft.Json;
@{
ViewData["Title"] = "CookUpdate";
}
2023-06-19 20:11:35 +04:00
<header>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</header>
2023-05-18 01:40:11 +04:00
<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" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.CookList, "Id", "FIO"))"></select></div>
</div>
<div class="row">
<div class="col-4">ФИО:</div>
2023-06-19 20:11:35 +04:00
<div class="col-8"><input type="text" name="FIO" id="FIO" value="" /></div>
2023-05-18 01:40:11 +04:00
</div>
<div class="row">
<div class="col-4">Должность:</div>
2023-06-19 20:11:35 +04:00
<div class="col-8"><input type="text" name="position" id="position" value="" /></div>
2023-05-18 01:40:11 +04:00
</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>
2023-06-19 20:11:35 +04:00
$(document).ready(function () {
$('#Id').change(function () {
var selectedCookId = $(this).val();
var cooks = @Html.Raw(JsonConvert.SerializeObject(ViewBag.CookList));
var selectedCook;
for (var i = 0; i < cooks.length; i++) {
if (cooks[i].Id == selectedCookId) {
selectedCook = cooks[i];
break;
}
}
if (selectedCook) {
$('#FIO').val(selectedCook.FIO);
$('#position').val(selectedCook.Position);
}
2023-05-18 01:40:11 +04:00
});
2023-06-19 20:11:35 +04:00
$('#Id').val($('#Id option:first').val()).change();
});
2023-05-18 01:40:11 +04:00
</script>