MVC Bootstrap LogOff

时间:2014-05-07 10:21:59

标签: javascript asp.net twitter-bootstrap asp.net-mvc-5

是否可以将MVC logoutForm或functianlity插入到.js文件中?

我检查用户是否在/View/Shared/_layout.cshtml页面中登录,如下所示:

@using Microsoft.AspNet.Identity

@if (Request.IsAuthenticated) 
{
    @Html.AntiForgeryToken()
    @Scripts.Render("~/bundles/bootstrapped")
} else {
    @Scripts.Render("~/bundles/bootstrap")
}

bootstrap.js:

$(document).ready(function(){
    $('head').prepend('<link rel="stylesheet" href="/Content/docs.css" type="text/css" media="screen">');
    $('body').prepend('<div id="panel"><div class="navbar navbar-inverse navbar-fixed-top" id="advanced"><span class="trigger"><strong></strong><em></em></span><div class="navbar-inner"><div class="container"><button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-top-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><div class="nav-collapse collapse nav-top-collapse"><ul class="nav"><li class="home"><a href="/" title="Home"><img src="/Images/tm_home.png" alt="Home"></a></li><li class=""><a href="/Home/Help" title="Help">Help</a></li><li><a href="/Account/Register" title="Register">Register</a></li><li class=""><a href="/Account/Login" title="Login">Login</a></li></ul></div></div></div></div></div>');
}); 

bootstrapped.js:

$(document).ready(function(){
    $('head').prepend('<link rel="stylesheet" href="/Content/docs.css" type="text/css" media="screen">');
$('body').prepend('<div id="panel"><div class="navbar navbar-inverse navbar-fixed-top" id="advanced"><span class="trigger"><strong></strong><em></em></span><div class="navbar-inner"><div class="container"><button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-top-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><div class="nav-collapse collapse nav-top-collapse"><ul class="nav"><li class="home"><a href="/" title="Home"><img src="/Images/tm_home.png" alt="Home"></a></li><li class=""><a href="/Home/Help" title="Help">Help</a></li><li class=""><a href="/Account/Manage" title="Manage">Manage</a></li><li class=""><a href="somethinghere" title="Logout">Logout</a></li></ul></div></div></div></div></div>');
});

我注意到在最初的WebApplication1 MVC项目中是/View/Shared/_LoginPartial.cshtml,其中包含以下内容:

@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage" })

<li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>

如果可能的话,我想把这个功能放到boostrapped.js文件中。

非常感谢任何帮助: - )

0 个答案:

没有答案