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 9191067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:35:50+00:00 2026-06-17T20:35:50+00:00

I am exploring a generic solution related to DropDownBox in Asp.net MVC with respect

  • 0

I am exploring a generic solution related to DropDownBox in Asp.net MVC with respect to loggedin User role. Following is the scenario:

If UserRole is X then the DropDown on webpageA must have multiple values.

If UserRole is Y then the Dropdown on webpageA must have single value and dropdown must be ReadONLY defaulted to single value.

Values will be provided by the controller through ViewBag to the view

Can someone help me with the Extension method for this scenario?

  • 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-06-17T20:35:51+00:00Added an answer on June 17, 2026 at 8:35 pm

    Here is a link to download the source code for MVC3. The file you’re looking for is mvc3-rtm-sources\mvc3\src\SystemWebMvc\Mvc\Html\SelectExtensions.cs. That file contains all of the Extension methods for the DropDownList and DropDownList for.

    What you’d be looking for is something similar to the following:

    [SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification = "This is an appropriate nesting of generic types")]
    public static MvcHtmlString DropDownListForRoles<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, UserRole role, IDictionary<string, object> htmlAttributes) {
        if (role == 'X') {
            //edit the select list as necessary
        }
        else if (role == 'Y') {
            // have the single value
            // add the read-only attribute to htmlAttributes
        }
        return DropDownListHelper(htmlHelper, expression, selectList, htmlAttributes);
    }
    

    That should at least be a good starting point with what you’re looking for. Without more details, I can only really give you pseudo-code. However, you should be able to tweak what you need from there.

    Don’t forget to check out the different overrides that they have for all of the functions. You may not think you need them now, but it’s always nice to know that all of the options are there should something change later on. Do those like they have them, and just have those methods return the method you create call the method with all of the possible parameters, passing in null values where necessary.

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

Sidebar

Related Questions

I'm exploring the possibilities of the ASP.net Webpages 2 with Razor, and trying to
I'm exploring alfresco action tag. Following action tag does not specify permission <action id=document-copy-to
I need to use a generic interface like the following: public interface IContainer<T> {
Following my question here I am exmploring ideas for a generic approach to document
Exploring Javascript (and coming from the Java world). I have the following line of
I am a ASP.NET Developer trying to learn Rails and RESTful approach. To understand,
while exploring jQuery I came up with the following weird script. I don't see
I am trying to build a generic method for exporting a list to excel.
Exploring a new data set: What is the easiest, quickest way to visualise many
I've been exploring methods for full-width background images combined with type. I found this

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.