48 lines
1.7 KiB
Plaintext
48 lines
1.7 KiB
Plaintext
@using Newtonsoft.Json;
|
|
@{
|
|
ViewData["Title"] = "DishUpdate";
|
|
}
|
|
<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.DishList, "Id", "DishName"))"></select></div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-4">Название:</div>
|
|
<div class="col-8"><input type="text" name="name" id="name" value="" /></div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-4">Цена:</div>
|
|
<div class="col-8"><input type="text" name="price" id="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>
|
|
$(document).ready(function () {
|
|
$('#Id').change(function () {
|
|
var selectedDishId = $(this).val();
|
|
var dishes = @Html.Raw(JsonConvert.SerializeObject(ViewBag.DishList));
|
|
var selectedDish;
|
|
for (var i = 0; i < dishes.length; i++) {
|
|
if (dishes[i].Id == selectedDishId) {
|
|
selectedDish = dishes[i];
|
|
break;
|
|
}
|
|
}
|
|
if (selectedDish) {
|
|
$('#name').val(selectedDish.DishName);
|
|
$('#price').val(selectedDish.Price);
|
|
}
|
|
});
|
|
$('#Id').val($('#Id option:first').val()).change();
|
|
});
|
|
</script> |