48 lines
1.7 KiB
Plaintext
48 lines
1.7 KiB
Plaintext
@using Newtonsoft.Json;
|
|
@{
|
|
ViewData["Title"] = "CookUpdate";
|
|
}
|
|
<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" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.CookList, "Id", "FIO"))"></select></div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-4">ФИО:</div>
|
|
<div class="col-8"><input type="text" name="FIO" id="FIO" value="" /></div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-4">Должность:</div>
|
|
<div class="col-8"><input type="text" name="position" id="position" value="" /></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 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);
|
|
}
|
|
});
|
|
$('#Id').val($('#Id option:first').val()).change();
|
|
});
|
|
</script> |