I'm attempting to invoke an ActionResult from a Controller in JavaScript.
The ActionResult is located in my AdminController
.
[HttpPost]
public ActionResult Logout()
{
return RedirectToAction("Login", "Login");
}
This is the Logout button
in AdminView.
<a class="navbar-link" id="logout" name="logout" href="#">
ログアウト
</a>
Now, I am trying to create an event in JavaScript.
$("#logout").click(function () {
swal({
title: "ログアウト?",
text: "アカウントからサインアウトしますか?",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willLogout) => {
if (willLogout) {
//swal("Poof! Your imaginary file has been deleted!", {
// icon: "success",
//});
$.ajax({
url: "/Admin/Logout",
type: 'POST',
success: function (result) {
document.location.reload(true);
},
error: function (result) {
}
});
}
});
});
The main objective here is to redirect the user to the Login Page using the Controller.
I tried placing the swal("Poof")...
inside the .then(willLogout)
and it worked fine.
However, when I attempt to call the ActionResult using ajax, it doesn't work as expected.
Upon checking the console, it appears that nothing is being displayed.
I'm unsure of what mistake I might be making.
How can I effectively call the ActionResult
from Controller to the JavaScript file using an Ajax
call?