45 lines
1.5 KiB
Plaintext
45 lines
1.5 KiB
Plaintext
@using Newtonsoft.Json;
|
|
@{
|
|
ViewData["Title"] = "UpdateLunch";
|
|
}
|
|
<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.Lunches, "Id", "Id"))"></select></div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-4">Название обеда:</div>
|
|
<div class="col-8">
|
|
<input type="text" name="name" id="name" />
|
|
</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 selectedLunchId = $(this).val();
|
|
var lunches = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Lunches));
|
|
var selectedLunch;
|
|
for (var i = 0; i < lunches.length; i++) {
|
|
if (lunches[i].Id == selectedLunchId) {
|
|
selectedLunch = lunches[i];
|
|
break;
|
|
}
|
|
}
|
|
if (selectedLunch) {
|
|
$('#name').val(selectedLunch.LunchName);
|
|
}
|
|
});
|
|
$('#Id').val($('#Id option:first').val()).change();
|
|
});
|
|
</script> |