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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:58:21+00:00 2026-05-23T00:58:21+00:00

Background – I’m trying to populate a drop down list with state information from

  • 0

Background – I’m trying to populate a drop down list with state information from a database. I’d like the full state name to be the option and the state abbreviation to be the value. Example:

<option value="AL">ALABAMA</option>

Current Progress – The full state names and abbreviations already exist in the DB. I’ve successfully populated the DDL with full state names from the DB. Here’s the code I’ve used to do this (minus stuff I’ve deemed irrelevant).

Model Context (generated from template):

Partial Public Class BrokerCRMEntities
    Public Property States() As DbSet(Of State)
End Class

State Model (generated from template):

Partial Public Class State
    Public Property StateAbbrev As String
    Public Property StateFull As String
End Class

Controller:

Dim db As BrokerCRMEntities = New BrokerCRMEntities
Dim StateList = New List(Of String)()
Dim StateQuery = From d In db.States
                 Order By d.StateFull
                 Select d.StateFull
StateList.AddRange(StateQuery)
ViewBag.State = New SelectList(StateList)

View:

@ModelType IEnumerable(Of BrokerCRM.BrokerCRMEntities)
@Html.DropDownList("State", "")

This code produces a DDL which contains full state names. Example:

<option>ALABAMA</option>

Question – In addition to populating full state names like I’ve done above, I’d also like to populate the value of the select options in the same DDL with the state abbreviations in my DB/model. How is this done?

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-23T00:58:21+00:00Added an answer on May 23, 2026 at 12:58 am

    I would recommend you using a view model along with a strongly typed view and DropDownListFor helper. So as always start with the view model:

    Public Class StatesViewModel
        Public Property SelectedState As String
        Public Property States As IEnumerable(Of State)
    End Class
    

    then the controller:

    Public Function Index() As ActionResult
        ' TODO: use ctor DI of the repository
        Dim db = New BrokerCRMEntities()
        Dim model = New StatesViewModel() With { _
            Key .States = db.States.OrderBy(Function(x) x.StateFull) _
        }
        Return View(model)
    End Function
    

    and finally the view:

    @ModelType IEnumerable(Of StatesViewModel)
    @Html.DropDownListFor(
        Function(x) x.SelectedState,
        New SelectList(Model.States, "StateAbbrev", "StateFull")
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I am trying to create a copy of a business object I have
Background: writing an automated release script to export changed files between versions from SVN
Background I'm trying to get obtain a unique identifier out of a computer and
Background: I'm using Google's protobuf , and I would like to read/write several gigabytes
Background I have a web app that will create an image from user input.
background-position: -200px 0; one site says it crops an image from the bottom and
Background I've got the following tree of objects: Name Project Users nil John nil
Background: I have a little video playing app with a UI inspired by the
Background: At my company we are developing a bunch applications that are using the
Background: Some time ago, I built a system for recording and categorizing application crashes

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.