When the json returns false or true from the controller, I send a message to the user with sweet alert 2 depending on the situation. But if my code enters the catch, I want to redirect an error page. But sweet alert 2 detects the value as false and produces a message, and I cannot see the error page. What I tried; I tried if a json object is returned from the controller, sweet alert should work, otherwise it shouldn't work. But I couldn't see any error page.
Controler :
public ActionResult Register(UsersRegister users)
{
...............
{
try
{
...................
else
{
return Json(new { result = false, message = "Kayıt olurken bir sorun oluştu! Lütfen daha sonra tekrar deneyin." });
}
}
}
catch (Exception ex)
{
return View("~/Views/Shared/Error.cshtml");
}
}
........................
}
Js :
function registerSuccess(response) {
if (response.result === true) {
Swal.fire({
title: 'Başarılı!',
text: response.message,
icon: 'success',
showConfirmButton: false,
timer: 3000,
});
$(".register-inputs").val("");
}
if (response.result === false) {
Swal.fire({
title: 'Başarısız!',
text: response.message,
icon: 'error',
confirmButtonText: 'Tamam',
});
hideOverlay();
}
}