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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:09:29+00:00 2026-05-27T18:09:29+00:00

How would I configure my ViewModel and View to support a dropdown list that

  • 0

How would I configure my ViewModel and View to support a dropdown list that contained the following Enum:

public enum PersonType
{
   Bride,
   Groom
}

I would want the text of the dropdown to show “Bride”, “Groom” and the value to be 0 and 1 respectively. I would want to configure a default (either Bride or Groom) for the View as well. The purpose of this is for a “Create” form that I would post and later determine which option was selected (I’m guessing I would need an int within my ViewModel to track what the user selected). How would this get wired up? I’m using Razor.

  • 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-27T18:09:30+00:00Added an answer on May 27, 2026 at 6:09 pm
    public enum PersonType
    {
       Bride=0,
       Groom=1
    }
    

    in your model you will have a property like

    public class mymodel{
    
    [Required(ErrorMessage="this field is required")]
    public int ID{get;set;}
    public IEnumerable<KeyValuePair<string, string>> _list{get;set}
    }
    

    in your controller

    mymodel model = new mymodel();
    
    model._list=Enum.GetNames(typeof(PersonType))
                 .Select(x => new KeyValuePair<string, string>(x, x.ToString()));
    return View(model);
    

    and in your view

    @Html.DropDownListFor(x=>x.ID,new SelectList(model._list,"key","value"))
    @ValidationMessageFor(x=>x.ID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to configure the tree view component so that would be the topmost
How would you configure annotations in the following example code? I'd like to stick
I would like to configure my local SVN server to support both a global
How would you configure the following WCF Data Services fluently in C#? <configuration> ...
How would one configure trac to allow anonymous submission of tickets?
How would you configure/handle extraneous/optional URLs entities (aliases, maybe)? SO is a good example:
I would like to configure asp.net process to run under an account with domain
I would like to be able to merge two files into one during configure
How can I configure the NppExec plugin for Notepad++? I would like NppExec to
On my asp webforms app I would do the log4net initialization; log4net.Config.XmlConfigurator.Configure(); on global.asax

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.