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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:17:05+00:00 2026-05-15T12:17:05+00:00

I am new to ASP.net MVC and I am having trouble getting dropdown lists

  • 0

I am new to ASP.net MVC and I am having trouble getting dropdown lists to work correctly.

I have a strongly typed view that is attempting to use a Html.DropDownListFor as follows:

<%=Html.DropDownListFor(Function(model) model.Arrdep, Model.ArrdepOptions)%>

I am populating the list with a property in my model as follows:

Public ReadOnly Property ArrdepOptions() As List(Of SelectListItem)
    Get
        Dim list As New List(Of SelectListItem)
        Dim arriveListItem As New SelectListItem()
        Dim departListItem As New SelectListItem()
        arriveListItem.Text = "Arrive At"
        arriveListItem.Value = ArriveDepart.Arrive
        departListItem.Text = "Depart At"
        departListItem.Value = ArriveDepart.Depart
        Select Case Me.Arrdep
            Case ArriveDepart.Arrive : arriveListItem.Selected = True
            Case Else : departListItem.Selected = True
        End Select
        list.Add(departListItem)
        list.Add(arriveListItem)
        Return list
    End Get
End Property

The Select Case works find and it sets the right SelectListItem as Selected, but when my view renders the dropdown list no matter what is marked as selected the generated HTML does not have anything selected.

I am obviously doing something wrong or missing something, but I can’t for the life of me figure out what.

  • 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-15T12:17:05+00:00Added an answer on May 15, 2026 at 12:17 pm

    It turns out I had to write a dropdown list helper. I found the article here. Here is my code in case someone else needs it. It is roughly translated to VB from the C# example in the article.

    Imports System.Linq.Expressions
    Imports System.Runtime.CompilerServices
    
    Namespace Helpers
    
        Public Module HtmlDropDownExtensions
    
            <Extension()> _
            Public Function EnumDropDownList(Of TEnum)(ByVal htmlHelper As HtmlHelper, ByVal name As String, ByVal selectedValue As TEnum) As MvcHtmlString
    
                Dim values As IEnumerable(Of TEnum) = [Enum].GetValues(GetType(TEnum))
    
                Dim list As New List(Of SelectListItem)
                For Each value As TEnum In values
                    Dim selectListItem As New SelectListItem()
                    selectListItem.Text = value.ToString()
                    selectListItem.Value = value.ToString()
                    selectListItem.Selected = (value.Equals(selectedValue))
                    list.Add(selectListItem)
                Next
                Dim items As IEnumerable(Of SelectListItem) = list
    
                Return htmlHelper.DropDownList(name, items)
    
            End Function
    
            <Extension()> _
            Public Function EnumDropDownListFor(Of TModel, TEnum)(ByVal htmlHelper As HtmlHelper(Of TModel), ByVal expression As Expression(Of Func(Of TModel, TEnum))) As MvcHtmlString
    
                Dim metadata As ModelMetadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData)
    
                Dim values As IEnumerable(Of TEnum) = [Enum].GetValues(GetType(TEnum))
    
                Dim list As New List(Of SelectListItem)
                For Each value As TEnum In values
                    Dim selectListItem As New SelectListItem()
                    selectListItem.Text = value.ToString()
                    selectListItem.Value = value.ToString()
                    selectListItem.Selected = (value.Equals(metadata.Model))
                    list.Add(selectListItem)
                Next
                Dim items As IEnumerable(Of SelectListItem) = list
    
                Return htmlHelper.DropDownListFor(expression, items)
    
            End Function
    
        End Module
    
    End Namespace
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to ASP.NET MVC; something I'm having trouble with is getting data from
I'm having trouble getting our multi-instance performance counter to work in ASP.NET MVC 3.
I'm relatively new to ASP.NET MVC so I'm having a little trouble with this
I am having problem getting my partial view to render in ASP.Net MVC 1.0
I'm fairly new to ASP.NET MVC, and I'm having a little trouble with scripts...
I am using ASP.Net MVC 2 and have trouble getting a DropDownList to bind
I'm a bit new to ASP .NET MVC and I'm having trouble understanding the
I have a new asp.net mvc project and i am trying to figure out
I have created the following project structure for my new asp.net mvc project any
I'm using ASP.NET MVC (1.0), Spark View Engine (1.0) and SubSonic (3.0.0.3). I'm having

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.