问题
I'm using the MVC template on Asp.net MVC 4, and I have a UserProfile
(t class with the UserType
(this field receive only 2 values, "Ouvinte" and "Musico") field, that works like roles in application, right?
My idea is, make a verification on _Layout.cshtml to know what is the UserType that are logged on application and modify the navbar on top.
THIS IS MY NAVBAR ON _Layout
<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>
My doubt is, how can i call the userProfile here to do these validation?
来源:https://stackoverflow.com/questions/26309067/update-layout-for-different-type-of-users