ASP.NET MVC检查里面查看角色 [英] ASP.NET MVC Check role inside view
本文介绍了ASP.NET MVC检查里面查看角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我看来,我有我想隐藏,并根据用户的角色如何能做到这一点的看法例如内表现出一定的管理员联系。
<%= IF(检查用户是否角色admin){%GT;
< DIV CLASS =工具>
< UL>
<李班=编辑><%= Html.ActionLink(编辑,编辑,新{ID = Model.storyId})%GT;< /李>
<李班=删除><%= Html.ActionLink(删除,删除,新{ID = Model.storyId})%GT;< /李>
< / UL>
< / DIV>
&下;(%)=}%GT;
解决方案
<%,如果(Page.User.IsInRole(管理)){%GT;<%}%GT;
然而,这在我看来是一个可怕的想法。这是更好地让ViewData的或示范重新present什么看法显示,视图可以简单地检查查看数据。控制器基类或者一个动作过滤器可以重复使用的这个非常简单,让code在一个地方存在。
In my View I have some admin links that I would like to hide and show based on user role how can do this inside the view e.g.
<%= if(CHECK IF USER ROLE ADMIN) { %>
<div class="tools">
<ul>
<li class="edit"><%= Html.ActionLink("Edit", "Edit", new { id = Model.storyId }) %></li>
<li class="delete"><%= Html.ActionLink("Delete", "Delete", new { id = Model.storyId }) %></li>
</ul>
</div>
<%= } %>
解决方案
<% if (Page.User.IsInRole("Admin")){ %>
<%}%>
However this is a terrible idea in my opinion. It is better to let the ViewData or Model represent what the view is to display, and the view can simply check the view data. A controller base class or an action filter can make repetitive use of this very simple and allow the code to exist in one place.
这篇关于ASP.NET MVC检查里面查看角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文