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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:54:38+00:00 2026-05-24T13:54:38+00:00

Ok here is my challenge: I want to create a dropdownlist with three strings

  • 0

Ok here is my challenge:
I want to create a dropdownlist with three strings in my Register View – “Please Select”, “I am a client”, and “I am a vendor”. When the user selects the “I am a client” and submits he is added to the “Client” role. When the user selects the “I am a Vendor” role he is added to the “Vendor” role. If the user doesn’t select either and leaves on “Please select” validation occurs.

I can get the roles to directly populate via the ViewBag. Here’s how:

Register.cshtml –

        <div class="editor-label">
            @Html.LabelFor(m => m.Role, "I am a:")
        </div>
        <div class="editor-field">
            @Html.DropDownList("Role", ViewBag.Roles as SelectList,"Please Select")
        </div>

AccountModel.cs –

public class RegisterModel
{

    [Required]
    [Display(Name = "Role")]
    public string Role { get; set; }

AccountController.cs –

    public ActionResult Register()
    {

        ViewBag.Roles = new SelectList(Roles.GetAllRoles().ToList());
        return View();

What I still need to accomplish –
Currently the dropdownlist only populates the actual roles. This is not what I want though.

How do I instead create a dropdownlist for three strings in my Register View – “Please Select”, “I am a client”, and “I am a vendor”.

I have no hair left on this one and will be grateful to anyone who can help me to figure this one out. Thanks.

  • 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-24T13:54:39+00:00Added an answer on May 24, 2026 at 1:54 pm

    Something similar to below would work perfectly:

    public class RegisterModel
    {
    
        [Required]
        [Display(Name = "Role")]
        public string Role { get; set; }
    

    Then you can have something similar to this in your view.

    @Html.DropDownListFor(x => x.Role, new[] {
    new SelectListItem() {Text = "I am a vendor", Value = "Vendor"},
    new SelectListItem() {Text = "I am a client", Value = "Client"}
    }, "Pick a basket")
    

    Edit: String is a reference type and is nullable by default.

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

Sidebar

Related Questions

I have three models of concern here: User Fight FightPunches Punches The associations are
Here's the challenge: depending on the incoming URL I want to display a specific
Ok here is my challenge, I have some <h1> tags that I want to
Here is a challenge question I've got from Linux system programming lecture. Any of
Here's my (code golf) challenge: Take two arrays of bytes and determine if the
Here's a problem I ran into recently. I have attributes strings of the form
I have an interesting challenge that I'm wondering if anyone here can give me
So here’s the challenge. Given 2 integers named a and b: // Find the
So here's the challenge. I need to use C# to back up a database
My challenge here is to search a webpage to attempt to find all of

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.