Christian Pliso Christian Pliso - 6 months ago 5
HTML Question

LogOut not working properly

I have some trouble with logout on my page. i have a controller with this

public ActionResult LogOut()
return RedirectToAction("Index", "Home");

And so a view called LogOut. I've put an href on it with a button :

<li><a class="logout" href="~/Views/Account/LogOut.cshtml">Se d├ęconnecter</a></li>

but when i click it keeps saying me your page couldn't been found etc...

But strange thing is this, if i put in my adress bar, the path to the LogOut view it works and i'm disconnected, someone knows why ?


You should give href like this instead of path to cshtml file:

 <li><a class="logout" href="@Url.Action('Logout', 'ControllerName')">Se d├ęconnecter</a></li>

it will hit LogOut Action Method then will Render your view Appropriately