ComputerHardwareStore_YouAr.../ComputerHardwareStore/VendorClient/Views/Home/CommentUpdate.cshtml
2024-05-01 19:39:07 +04:00

53 lines
1.6 KiB
Plaintext

@{
ViewData["Title"] = "CommentUpdate";
}
<div class="text-center">
<h2 class="display-4 mb-5">Обновить комметрарий</h2>
</div>
<form method="post">
<div class="row mb-3">
<div class="col-4">Комментарий:</div>
<div class="col-8">
<select id="comment" name="comment" class="form-control" asp-items="@(new SelectList(@ViewBag.Comments,"Id", "Text"))"></select>
</div>
</div>
<div class="row mb-3">
<div class="col-4">Заголовок:</div>
<div class="col-8"><input type="text" id="title" name="title" /></div>
</div>
<div class="row mb-3">
<div class="col-4">Текст:</div>
<div class="col-8"><input type="text" id="text" name="text" /></div>
</div>
<div class="row mb-3">
<div class="col-4">Сборка:</div>
<div class="col-8">
<select id="build" name="build" class="form-control" asp-items="@(new SelectList(@ViewBag.Builds,"Id", "Name"))"></select>
</div>
</div>
<div class="text-center ">
<input type="submit" value="Обновить" class="btn btn-success ps-5 pe-5" />
</div>
</form>
<<script>
$('#comment').on('change', function () {
getData();
});
function getData() {
var commentId = $('#comment').val();
var commentData = @Html.Raw(Json.Serialize(ViewBag.Comments));
var selectedComment = commentData.find(function (comment) {
return comment.id == commentId;
});
if (selectedComment) {
$("#title").val(selectedComment.title);
$("#text").val(selectedComment.text);
$("#build").val(selectedComment.buildId).change(); // <!-- в работоспособности не уверен -->
}
}
</script>