隐藏和可见Layout.cshtml在Asp.net MVC4用户角色的基础上,div标签(剃刀) [英] Hide and visible the div tags of Layout.cshtml on the basis of user role in Asp.net MVC4(Razor)

查看:519
本文介绍了隐藏和可见Layout.cshtml在Asp.net MVC4用户角色的基础上,div标签(剃刀)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪些是有一个名为用户和其他菜单角色的一些菜单和母版页是管理员的角色,所以我很愿意是检查用户和角色,并表现出一定的div标签和隐藏更为用户角色的基础上

I am having a master page which is having some menus for a Role called user and other menus are for the role of Admin, So what i am willing is to check the role of the user and and show some div tags and hide others on the basis of user role.

由于,我们没有控制器layout.cshtml,所以我怎么可以设置为视图模型布局视图
其中,我可以检查当前用户的角色

如何基于所述layout.cshtml检查做作用

How to do role based checking on the layout.cshtml.

我已经通过跟随着的问题,但现在它没有得到回答。

I have been through followin question but it has not been answered by now

<一个href=\"http://stackoverflow.com/questions/11829937/how-to-show-or-hide-controls-based-on-roles-asp-net-mvc-4-razor\">How要显示或隐藏基于角色的控制 - ASP.NET MVC 4剃刀

那么,请告诉我可能的解决方案和方式将根据在layout.cshtml检查是最好的申请角色

So,Please tell me the possible solution and which way would be the best for applying role based checking in layout.cshtml

推荐答案

您可以使用<$c$c>User.IsInRole方法:

You could use the User.IsInRole method:

@if (User.IsInRole("admin"))
{
    <li>Only the admin can see this menu item</li>
}

这篇关于隐藏和可见Layout.cshtml在Asp.net MVC4用户角色的基础上,div标签(剃刀)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆