- вынес скрипт в файл.

- поправил фронт.
parent 235043e7
...@@ -8,26 +8,28 @@ ...@@ -8,26 +8,28 @@
<h2>@Model.Name</h2> <h2>@Model.Name</h2>
<div class="card mb-3"> <div class="card mb-3">
<img class="card-img-top w-50" src="~/@Model.Image" alt="Card image cap"> <div class="container">
<div class="card-body"> <img class="card-img-top w-50" src="~/@Model.Image" alt="Card image cap">
<h5 class="card-title">@Model.Brand.Name</h5> <div class="card-body">
<p class="card-text">@(Model.Price.ToString("C2"))</p> <h5 class="card-title">@Model.Brand.Name</h5>
</div> <p class="card-text">@(Model.Price.ToString("C2"))</p>
@if (User.Identity.IsAuthenticated)
{
<form id="feedbackForm">
<div class="form-group">
<label for="text">Добавьте отзыв о телефоне</label>
<input type="text" class="form-control" id="text" placeholder="Минимальная длина отзыва 10 символов">
<input type="text" hidden name="phoneId" id="@Model.Id">
<button type="submit">Отправить</button>
</div> </div>
</form> @if (User.Identity.IsAuthenticated)
} {
else <form class="mb-3" id="feedbackForm">
{ <div class="form-group">
<a asp-action="Login" asp-controller="Account">Авторизируйтесь для добавления отзыва</a> <label for="text">Добавьте отзыв о телефоне</label>
} <input type="text" class="form-control" id="text" placeholder="Минимальная длина отзыва 10 символов">
<input type="text" hidden name="phoneId" id="@Model.Id">
<button class="my-3" type="submit">Отправить</button>
</div>
</form>
}
else
{
<a asp-action="Login" asp-controller="Account">Авторизируйтесь для добавления отзыва</a>
}
</div>
</div> </div>
<div id="feedbacks"> <div id="feedbacks">
@foreach (var feedBack in Model.Feedbacks) @foreach (var feedBack in Model.Feedbacks)
...@@ -35,23 +37,3 @@ ...@@ -35,23 +37,3 @@
await Html.RenderPartialAsync("PartialViews/FeedbackPartialView", feedBack); await Html.RenderPartialAsync("PartialViews/FeedbackPartialView", feedBack);
} }
</div> </div>
@section Scripts
{
<script >
$(document).ready(function (){
$("#feedbackForm").on("submit", function (e){
e.preventDefault();
let phoneId = $("input[name=phoneId]");
let text = $("#text");
let feedback = {
text: text.val(),
phoneId: phoneId.attr('id')
};
$.post(`@Url.Action("Create", "Feedback")`, feedback, function (response){
$('#feedbacks').before(response);
})
})
})
</script>
}
...@@ -8,4 +8,19 @@ ...@@ -8,4 +8,19 @@
$('#results') $('#results')
.load(`https://localhost:5001/Account/SearchAccounts?searchTerm=${searchTerm}`); .load(`https://localhost:5001/Account/SearchAccounts?searchTerm=${searchTerm}`);
}) })
});
$(document).ready(function (){
$("#feedbackForm").on("submit", function (e){
e.preventDefault();
let phoneId = $("input[name=phoneId]");
let text = $("#text");
let feedback = {
text: text.val(),
phoneId: phoneId.attr('id')
};
$.post('https://localhost:5001/feedback/create', feedback, function (response){
$('#feedbacks').before(response);
});
});
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment