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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:34:05+00:00 2026-06-04T07:34:05+00:00

I have a constants values such as Required,Optional, and Hidden. I want this to

  • 0

I have a constants values such as “Required”,”Optional”, and “Hidden”. I want this to bind in the dropdownlist. So far on what I’ve done is the below code, this is coded in the view. What is the best way to bind the constant values to the dropdownlist? I want to implement this in the controller and call it in the view.

@{
    var dropdownList = new List<KeyValuePair<int, string>> { new KeyValuePair<int, string>(0, "Required"), new KeyValuePair<int, string>(1, "Optional"), new KeyValuePair<int, string>(2, "Hidden") };
    var selectList = new SelectList(dropdownList, "key", "value", 0); 

} 

Bind the selectList in the Dropdownlist

@Html.DropDownListFor(model => model.EM_ReqTitle, selectList)
  • 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-04T07:34:06+00:00Added an answer on June 4, 2026 at 7:34 am

    Judging by the property EM_RegTitle I’m guessing that the model you’re using is auto-generated from a database in some way. Maybe Entity Framework? If this is the case, then you should be able to create a partial class in the same namespace as your ORM/Entity Framework entities and add extra properties. Something like:

    public partial class MyModel
    {
        public SelectList MyConstantValues { get; set; }
    }
    

    You can then pass your SelectList with the rest of the model.

    There are usually hangups from using ORM/EF entities through every layer in your MVC app and although it looks easy in code examples online, I would recommend creating your own View Model classes and using something like AutoMapper to fill these views. This way you’re only passing the data that the views need and you avoid passing the DB row, which could contain other sensitive information that you do not want the user to view or change.

    You can also move the logic to generate your static value Select Lists into your domain model, or into a service class to help keep reduce the amount of code and clutter in the controllers.

    Hope this helps you in some way!

    Example…

    Your View Model (put this in your “Model” dir):

    public class MyViewModel
    {
        public SelectList RegTitleSelectList { get; set; }
    
        public int RegTitle { get; set; }
    }
    

    Your Controller (goes in the “Controllers” dir):

    public class SimpleController : Controller
    {
        MyViewModel model = new MyViewModel();
    
        model.RegTitle = myEfModelLoadedFromTheDb.EM_RegTitle;
        model.RegTitleSelectList = // Code goes here to populate the select list.
    
        return View(model);
    }
    

    Now right click the SimpleController class name in your editor and select “Add View…”.

    Create a new view, tick strongly typed and select your MyViewModel class as the model class.

    Now edit the view and do something similar to what you were doing earlier in your code. You’ll notice there should now be a @model line at the top of your view. This indicates that your view is a strongly typed view and uses the MyViewModel model.

    If you get stuck, there are plenty of examples online to getting to basics with MVC and Strongly Typed Views.

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

Sidebar

Related Questions

I have always prefixed my Constants with CN_ as shown below but I am
If I have an applescript snippet such as this tell application Finder set thePath
so i have a list where i need to add new values constantly but
I have a file that defines constant variables, like this: define_vars.php <? define(something,value); define(something1,value);
I have several constants that I use, and my plan was to put them
in my config.php where i have all constants i set the PATH to a
I've noticed many (all?) PHP constants have a single-letter prefix, like E_NOTICE , T_STRING
As python does not have concept of constants, would it be possible to raise
I have a Class named Constants that contains all the constant variable in my
I have 3 String arrays with constants. eg: String[] digit = {one, two, three};

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.