Update _Layout for different type of users

江枫思渺然 提交于 2020-01-06 18:13:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!