I have _layout
file what I want to show on different pages of my project
_layout.cshtml
<html>
xxxxx
</html>
my _layout
has a navigation bar I decided to create a partialView
to be able to show that navigation bar using another controller different from my "home" controller
NavegationController
public class NavBarController : Controller
{
// GET: NavBar
[ChildActionOnly]
public PartialViewResult BarraNavegacion()
{
return PartialView("~/Views/Shared/_navbar.cshtml");
}
[HttpPost]
public string LogOut(string data)
{
FormsAuthentication.SignOut();
return "bye";
}
}
In my _layout
I added the following line:
@{Html.RenderAction("BarraNavegacion", "NavBar");}
So far everything works, the navigation bar is displayed well
My navbar has a log out button, so I tried to implement the LogOut method using ajax
script Log out
//Boton salir
$('.salirUsuario').click(function() {
console.log("salio");
$.ajax({
url: 'LogOut',
method: "POST",
data: { data: "xx" },
async: false,
dataType: "json",
success: function (json) {
window.location.href = '@Url.Action("Login","Login")';
}
});
but received the following console error
jquery-3.4.1.min.js:2 POST http://localhost:9887/Home/LogOut 404 (Not Found)
I know The application tries to find the method/Action "LogOut
" in "Home
" (which is the view where I am at the moment), but how do I go to NavBar / LogOut of the controller that I created called NavBar
and not go to "Home
"or any other view where I am at time?