- вынес скрипты редактирования отзывов в отдельный файл.

parent 66021ec2
......@@ -28,10 +28,11 @@ namespace PhoneStore.Controllers
[HttpPost]
public async Task<IActionResult> Create(FeedbackCreateViewModel model)
{
var validationResult = await _feedbackValidation.ValidateAsync(model);
// if (!validationResult.IsValid)
// {
// //TODO: сформировать сообщение
//TODO: сформировать сообщение
// return NotFound();
// }
var feedbackViewModel = _feedbackService.Create(model, User);
......
......@@ -38,37 +38,3 @@
@{
await Html.RenderPartialAsync("PartialViews/EditFeedbackModalPartial");
}
@section Scripts
{
<script >
$('#exampleModal').on('show.bs.modal', function (event) {
const button = $(event.relatedTarget);
const oldText = button.attr('text');
const username = button.attr('username');
const feedbackId = button.attr('feedbackId');
const modal = $(this);
modal.find('.modal-title').text('Редактируете от имени: ' + username);
const textarea = modal.find('.modal-body textarea');
textarea.text(oldText);
console.log(textarea.text())
console.log(feedbackId)
$('#feedback-edit-form').on('submit', function (submitEvent){
submitEvent.preventDefault();
$('#exampleModal').modal('hide');
fetch('https://localhost:5001/feedback/update', {
method: 'post',
body: JSON.stringify({id: feedbackId, text: textarea.val()}),
headers: {'content-type': 'application/json'}
}).then(response => {
console.log(response);
return response.text();
}).then(text => {
$(`div[id=${feedbackId}]`).html(text);
}).catch((error) => {
alert(error);
});
});
});
</script>
}
......@@ -49,5 +49,32 @@ $(document).ready(function () {
return true;
});
});
$('#exampleModal').on('show.bs.modal', function (event) {
const button = $(event.relatedTarget);
const oldText = button.attr('text');
const username = button.attr('username');
const feedbackId = button.attr('feedbackId');
const modal = $(this);
modal.find('.modal-title').text('Редактируете от имени: ' + username);
const textarea = modal.find('.modal-body textarea');
textarea.text(oldText);
$('#feedback-edit-form').on('submit', function (submitEvent){
submitEvent.preventDefault();
$('#exampleModal').modal('hide');
fetch('https://localhost:5001/feedback/update', {
method: 'post',
body: JSON.stringify({id: feedbackId, text: textarea.val()}),
headers: {'content-type': 'application/json'}
}).then(response => {
console.log(response);
return response.text();
}).then(text => {
$(`div[id=${feedbackId}]`).html(text);
}).catch((error) => {
alert(error);
});
});
});
});
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