c# - how to load a different _layout.cshtml depending on role? -


my app have different roles, 1 role global administrator, have options adding users, adding companies, etc.

the template bought has 1 _layout.cshtml, need loads different 1 depending on role of user.

one has different menu.

my viewstart

@{     layout = "~/views/shared/_layout.cshtml"; } 

and layouts.cshtml

<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>     <meta charset="utf-8" />     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta http-equiv="x-ua-compatible" content="ie=edge">      <title>inspinia | @viewbag.title</title>      <link href='https://fonts.googleapis.com/css?family=open+sans:400,300,600,700' rel='stylesheet' type='text/css'>     <!-- add local styles, plugins css file -->     @if (issectiondefined("styles"))         {@rendersection("styles", required: false)}      <!-- add jquery style direct - used jqgrid plugin -->     <link href="@url.content("~/scripts/plugins/jquery-ui/jquery-ui.css")" rel="stylesheet" type="text/css" />      <!-- primary inspinia style -->          @styles.render("~/font-awesome/css")                                                     @styles.render("~/content/css") </head> <body>      <!-- skin configuration box -->     @html.partial("_skinconfig")      <!-- wrapper-->     <!-- pageclass give ability specify custom style specific view based on action -->     <div id="wrapper" class="@html.pageclass()">          <!-- navigation -->         @html.partial("_navigation")          <!-- page wraper -->         <div id="page-wrapper" class="gray-bg @viewbag.specialclass">              <!-- top navbar -->             @html.partial("_topnavbar")              <!-- main view  -->             @renderbody()              <!-- footer -->             @html.partial("_footer")          </div>         <!-- end page wrapper-->          <!-- right sidebar -->         @html.partial("_rightsidebar")      </div>     <!-- end wrapper-->      <!-- section main scripts render -->     @scripts.render("~/bundles/jquery")     @scripts.render("~/bundles/bootstrap")     @scripts.render("~/plugins/slimscroll")     @scripts.render("~/bundles/inspinia")      <!-- skin config script - demo purpose-->     @scripts.render("~/bundles/skinconfig")      <!-- handler local scripts -->     @rendersection("scripts", required: false) </body> </html> 

everything works perfect, need create layouts.cshtml reference different navigation partial view , thats question comes in,

how can make app load specific layouts.csthml when user belongs specific role?

you can split layout 2 parts 1 normal users , other admin. there 2 or 3 types of way render layouts specified in this article using _viewstart.cshtml, or specifying layout in view or via action result.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -