I am new to MVC world. I have a nav
in my Layout file used by logged in users :
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Member")</li>
<li>@Html.ActionLink("My Profile", "MyProfile", "Member")</li>
<!-- User type Admin, then Admin Menu -->
<li>@Html.ActionLink("Admin Index", "AdminIndex", "Member")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<!-- Throws error /User/Logout not found -->
<li>@Html.ActionLink("Logout", "Logout", "User")</li>
<!-- Works Perfectly fine, but the link is on new line & different font/color/underlined -->
@if (Request.IsAuthenticated)
{
using (Html.BeginForm("Logout", "User", FormMethod.Post, new { id = "logoutForm" }))
{
<li><a href="javascript:document.getElementById('logoutForm').submit()">Logout</a></li>
}
}
</ul>
</div>
The @Html.ActionLink("Logout"
doesn't work. It throws "/User/Logout" not found Error
How to make that work like the below logout with <a href
??? Is the error b'coz in href, their is form and calling Form.Post method ??
Controller code :
public class UserController : Controller
{
// Registeration Action
[HttpGet]
public ActionResult Registeration() {..... }
// Login
[HttpGet]
public ActionResult Login() {.... }
// Login Post
[HttpPost]
public ActionResult Login(UserLogin userLogin, string returnUrl) { ...}
// Logout
[Authorize]
[HttpPost]
public ActionResult Logout()
{
FormsAuthentication.SignOut();
return RedirectToAction("Login", "User");
}
}
Can anyone please help me get this work !! Any help is highly appreciated.
Thanks