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

  • Home
  • SEARCH
  • 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 7166679
In Process

The Archive Base Latest Questions

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

This obviously is pretty basic question but I haven’t found my way around this:

  • 0

This obviously is pretty basic question but I haven’t found my way around this: I’m trying to create a dropdown list for an integer property of my Model, so I can populate the dropdown with a default list of values.

My controller looks like this:

ViewBag.MyListOfOptions = new SelectList(new int[] { 5, 15, 25, 50 });

And my view looks like this:

@Html.DropDownListFor(model => model.MyIntField, new SelectList(ViewBag.MyListOfOptions , [dataValueField], [dataTextField]))

Most examples I’ve found dataValueField and dataTextField are the properties that should be used in creating the dropdown, but I haven’t found a way on how to use DropDownListFor with value types

  • 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-28T14:27:10+00:00Added an answer on May 28, 2026 at 2:27 pm

    Because you created the SelectList from MyListOfOptions which is already a SelectList you can use “Text” and “Value”

    @Html.DropDownListFor(model => model.MyIntField, 
        new SelectList(ViewBag.MyListOfOptions , "Value", "Text"))
    

    But you don’t need to wrap again an SelectList, so this will also work:

    @Html.DropDownListFor(model => model.MyIntField,
        (IEnumerable<SelectListItem>)ViewBag.MyListOfOptions)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may seem like a basic/stupid/obviously-answered question, but I wanted to check: why use
This has to be a pretty basic question but I cannot for the life
This is obviously a rookie question about Adobe technologies, but I am seeking a
I'm pretty new to MVC so this may seem like an obvious question, but
I've got a pretty basic question that I can't wrap my head around (possibly
This is pretty weird. I have my Profiler open and it obviously shows that
Thinking that the answer to this is pretty obvious but here it goes: When
This is obviously a stupid question. I am coding in Eclipse both on Mac
So this is pretty basic, I know! Sorry, just one of those days. I've
Okay, so, this code is pretty basic. The user inputs an answer into a

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.