На кнопке удаления я отображаю сладкое предупреждение, которое работает нормально.Проблема в том, что когда я отправляю идентификатор объекта, который не существует, я получаю то же сообщение (которое я удаляю успешно).
Я хочу показать сообщение, если возникнет какая-либо ошибка (например, событие с таким идентификатором не найдено, я хочу создать новое сообщение и отобразить его как приятное предупреждение).
$('.deleteEvent').on('click', function () {
var $button = $(this);
var id = $button.data('id');
console.log("id", id);
var config = {
title: 'Are you sure',
type: 'info',
showCancelButton: true,
confirmButtonText: 'Yes',
cancelButtonText: ' No',
closeOnConfirm: false,
closeOnCancel: true
};
swal(config, function (isConfirm) {
if (isConfirm) {
console.log("lokac", window.location.origin);
var url = window.location.origin + '/events/delete?id=' + id;
$.post(url)
.done(function () {
var doneConfig = {
title: 'Succ....',
type: 'success',
confirmButtonText: 'Ok'
};
sweetAlert(doneConfig, function (done) {
if (done) {
window.location.reload();
}
});
})
.fail(function (error) {
var errorConfig = {
title: 'Not Found',
type: 'error',
confirmButtonText: 'Ok'
};
sweetAlert(errorConfig, function (done) {
if (done) {
window.location.reload();
}
});
});
}
});
});
и мой контроллер
public ActionResult Delete(int id)
{
if (id == default(int))
return RedirectToRoute(AppRoute.Events.EventsRoute);
id = -1;
try
{
var event =
DbContext.Event.FirstOrDefault(x => x.EventId == id);
if (event == null)
{
//If event is not found, I want to create a message which
//will be displayed on sweet alert
}
}
//.....
}