Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6038703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:15:39+00:00 2026-05-23T06:15:39+00:00

How do you do conditional content rendering in ASP.NET MVC depending on User.IsInRole() ?

  • 0

How do you do conditional content rendering in ASP.NET MVC depending on User.IsInRole()? Tried all matches i could find here, at SO but still not satisfied. I need to hide action links depending on user roles so first i thought of a helper like

public static MvcHtmlString ActionLink(this HtmlHelper html, string linkUrl, string linkText, object htmlAttributes, bool alwaysVisible, params string[] roles)

but then I realized that I often needed to hide the outer content too (for example, <li></li> in the menu where my links were placed into). I follow the recommendation from best practices and have UrlHelperExtension so my typical links look like:

<a href="@Url.SomeStuff()">some stuff</a>

and I can’t try the idea to implement the helper over RouteLink() that will grab AuthorizeAttribute from appropriate controller methods can I?. What’s your solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:15:39+00:00Added an answer on May 23, 2026 at 6:15 am

    I tend to use something along the lines of:

    @if (User.IsInRole("Role")) {
    <li>
      <a href="@Url.SomeStuff()">Some stuff</a>
    <li>
    }
    

    This way I can have multiple links per role if needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am faced with a problem with ASP.NET MVC 3 with the Razor rendering
I have these conditional css files <!--[if IE 7]><link rel=stylesheet type=text/css media=all href=/Content/css/ie7.css /><![endif]-->
I have a Content Page with drop down lists within an update panel: <asp:UpdatePanel
Is it a good idea to put all conditional CSS rules in one conditional
I am building an ASP.NET site using Visual Studio 2008 and have a page
<asp:UpdatePanel runat=server ID=udp_RemitEditor UpdateMode=conditional OnPreRender=LoadParameters> <ContentTemplate> <div id=div_RemitEditor style=width:225px; display: none;> <asp:UpdatePanel ID=upnl_RemitEditor runat=server
I have code like this on some aspx page in my Web Application: <asp:Content
Assume browser default settings, and content is sent without expires headers. user visits website,
Here's a simplified version of my Content tree. - Content - Articles - Article
What is the preferred Lift way to handle conditional content in a template? As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.