PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenManagerApp/Views/Home/DishUpdate.cshtml
2023-05-18 00:40:11 +03:00

38 lines
1.4 KiB
Plaintext

@{
ViewData["Title"] = "DishUpdate";
}
<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.DishList, "Id", "DishName"))"></select></div>
</div>
<div class="row">
<div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="name" value="" /></div>
</div>
<div class="row">
<div class="col-4">Цена:</div>
<div class="col-8"><input type="text" name="price" 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>
function populateFields() {
var selectedDishId = document.getElementById("dish").value;
var dishes = @Json.Serialize(ViewBag.CookList);
var selectedDish = dishes.find(function (dish) {
return dish.Id === selectedDishId;
});
if (selectedDish) {
document.getElementsByName("name")[0].value = selectedDish.DishName;
document.getElementsByName("price")[0].value = selectedDish.Price;
}
}
</script>