I am using ASP.NET MVC 4 for the first time, so I started with the default template.
In the _LoginPartial.cshmtl for Log off link I found the below code
@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })) {
@Html.AntiForgeryToken()
<a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
}
I was expecting a code like the one below, which I have been using in MVC 3.
@Html.ActionLink("Log off", "LogOff", "Account")
Please can someone help me understand as to why this is necessary, and its advantages if any. Thanks
There’s no big difference. MVC4 uses a HTML-form to logout, which is submitted via the javascript.
The advantage is that the new way (with the form) uses javascript to submit the form, which is why the page does not have to reload.