我在Asp.net MVC 4上使用MVC模板,我有一个UserProfile
(带有UserType
的t类(此字段只接收2个值,“Ouvinte”和“Musico” “)字段,就像应用程序中的角色一样,对吗?
我的想法是,在_Layout.cshtml上进行验证,以了解登录应用程序的UserType是什么,并在顶部修改导航栏。
这是我在_Layout上的NAVBAR
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">@Html.ActionLink("your logo here", "Index", "Home")</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("Usuario", "Usuario", "Home")</li>
<li>@Html.ActionLink("Musico", "Musico", "Home")</li>
</ul>
<ul class="nav navbar-nav navbar-right">
@if (!Request.IsAuthenticated){ //IF USER IS NOT LOGGED.
<li>@Html.ActionLink("Register", "Register", "Account")</li>
<li>@Html.ActionLink("Log In", "Login", "Account")</li>
}
else //DO A ELSEIF HERE IF THE USER HAS THE USERTYPE Musico
{
<li>@Html.ActionLink("Manage Account", "Manage", "Account")</li>
<li>@using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm" })) {
@Html.AntiForgeryToken()
<a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>}</li>
} //ANOTHER ELSE HERE TO VERIFY IF THE USER HAS USERTYPE Ouvinte
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
我的疑问是,如何在此处调用userProfile进行这些验证?