忽略@ Html.Action()如果用户不在角色 [英] Ignore @Html.Action() if user not in Role

查看:94
本文介绍了忽略@ Html.Action()如果用户不在角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的查看我渲染菜单 @ Html.Action(RenderMenu,管理) @ Html.Action(RenderMenu,经理)
其中action:


  [授权(角色=管理员)]
    公众的ActionResult RenderMenu()
    {
        返回查看();
    }


如果用户没有在角色的管理


  

@ Html.Action(RenderMenu,管理)忽略。


我该怎么办呢?
现在,我有无限的登录窗口。


解决方案

请参阅我的回答
<一href=\"http://stackoverflow.com/questions/20303162/asp-net-mvc3-is-really-based-on-roles-html-action/20303267#20303267\">Asp.net MVC3:真的是基于角色@ Html.Action()

您可以用得到它:

  @ Html.ActionBaseRole(RenderMenu,管理)

In my View i render menu @Html.Action("RenderMenu", "Admin") and @Html.Action("RenderMenu", "Manager") Where Action:

    [Authorize(Roles = "Admin")]
    public ActionResult RenderMenu()
    {
        return View();
    }

If user not in Role Admin

@Html.Action("RenderMenu", "Admin") just ignore.

how can I do it? Now, i have infinite login window.

解决方案

See my answer Asp.net MVC3: is really based on roles @Html.Action()

you can get it using:

@Html.ActionBaseRole("RenderMenu", "Admin")

这篇关于忽略@ Html.Action()如果用户不在角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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