ASP.NET MVC 4默认模板具有用于_LoginPartial.cshtml注销一个不同的语法 [英] ASP.NET MVC 4 Default template has a different syntax for logout in _LoginPartial.cshtml

查看:91
本文介绍了ASP.NET MVC 4默认模板具有用于_LoginPartial.cshtml注销一个不同的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC 4,第一次,所以我开始与默认模板。

I am using ASP.NET MVC 4 for the first time, so I started with the default template.

在_LoginPartial.cshmtl为注销链接,我发现下面的code

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>
}

我期待code类似下面,我一直使用MVC 3其中。

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

推荐答案

有没有很大的区别。 MVC4使用HTML的形式注销,这是通过javascript的提交。

There's no big difference. MVC4 uses a HTML-form to logout, which is submitted via the javascript.

它的优点是,新的方式(与表单)使用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.

这篇关于ASP.NET MVC 4默认模板具有用于_LoginPartial.cshtml注销一个不同的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆