44 lines
1.6 KiB
Plaintext
44 lines
1.6 KiB
Plaintext
|
@using Newtonsoft.Json;
|
||
|
@{
|
||
|
ViewData["Title"] = "CookUpdate";
|
||
|
}
|
||
|
<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" value="" /></div>
|
||
|
</div>
|
||
|
<div class="row">
|
||
|
<div class="col-4">Должность:</div>
|
||
|
<div class="col-8"><input type="text" name="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>
|
||
|
const cooks = [];
|
||
|
|
||
|
function populateFields() {
|
||
|
ViewBag.CookList.forEach(value => {
|
||
|
cooks.push(value);
|
||
|
});
|
||
|
var selectedCookId = document.getElementById("Id").value;
|
||
|
var selectedCook = cooks.find(function (cook) {
|
||
|
return cook.Id === selectedCookId;
|
||
|
});
|
||
|
//console.log(selectedCook.FIO);
|
||
|
if (selectedCook) {
|
||
|
document.getElementsByName("FIO")[0].value = selectedCook.FIO;
|
||
|
document.getElementsByName("position")[0].value = selectedCook.Position;
|
||
|
}
|
||
|
console.log(document.getElementsByName("FIO")[0].value);
|
||
|
}
|
||
|
</script>
|