2

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.

4 Answers4

0

Make if in razor view to check if user is in needed role. You could use (User.IsInRole("Adm inistrators"))

There was similar discussion here asp.net MVC3 razor: display actionlink based on user role

Community
  • 1
  • 1
Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
0

You can use this:

@if (Page.User.IsInRole("Admin")) {   
    @Html.Action("RenderMenu", "Admin")
}
YD1m
  • 5,845
  • 2
  • 19
  • 23
0

I have a answer. You may try it ......

@{
    if(User.IsInRole("Admin"))
       {
          @Html.Action("RenderMenu", "Admin")
          @Html.Action("RenderMenu", "Manager")
       }
   else
      {
@Html.Action("RenderMenu", "Manager")

     }
}
Atish Kumar Dipongkor
  • 10,220
  • 9
  • 49
  • 77
0

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

you can get it using:

@Html.ActionBaseRole("RenderMenu", "Admin")
Community
  • 1
  • 1
Ilya Sulimanov
  • 7,636
  • 6
  • 47
  • 68