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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:13:39+00:00 2026-05-16T22:13:39+00:00

I have a view that is displaying a Drop down list using the HTML

  • 0

I have a view that is displaying a Drop down list using the HTML helper DropDownListFor

<%: Html.DropDownListFor(Function(model) model.Manufacturer, New SelectList(Model.ManufacturerList, Model.Manufacturer))%>

My controller is passing the View a ViewModel containing the Manufacturer and the ManufacturerList

Function Search(ByVal itemSrch As ItemSearchViewModel) As ActionResult

     'some code mapping and model code'

     Return View(itemSrch)

End Function

My ViewModel is nothing crazy just fills the ManufacturerList with a list of string values and then the Manufacturer property is just a string value containing the selected value from the drop down list.

Public Property Manufacturer As String

Public Property ManufacturerList() As List(Of String)

I’m having an issue with the view setting the selected value on the drop down list if we are reloading the Search View. I’ve checked the View Model (ItemSearchViewModel) when it comes into the Search function and the Manufacturer is populated with the proper selected value and successfully passes that value back to the Search View. At some point the data passed to the view doesn’t seem to populate the selected value, was wondering if anyone had some ideas on why this is happening and what I can do to fix it.

Thanks

  • 1 1 Answer
  • 1 View
  • 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-16T22:13:39+00:00Added an answer on May 16, 2026 at 10:13 pm

    Didn’t get much for answers on this so started digging into how I could fix this somewhat easily. Also in my research this seemed to be a common problem for many people with the DropDownListFor HTML Helper. I figured there had to be a way to get this working since I knew the selected value property from my ViewModel was actually getting passed to the View. So javascript and jQuery to the rescue, I ended up trying to set the selected value using the jQuery .ready function and was able to successfully get this to work. So here’s my jQuery fix:

    $(document).ready(function() {
    
        $("#Manufacturer").val("<%: Model.Manufacturer %>");
    
    });
    

    For sake of making this easy to follow I used the full .ready syntax, or you can just use $(function () { ‘code’ });

    If you want to solve this without using jQuery you can just use basic javascript syntax as well, it’ll look something like this:

    document.getElementByID("Manufacturer").Items.FindByValue("<%: Model.Manufacturer %>").Selected = true;
    

    If you using the plain javascript call make sure to call this when the page is done loading data to the dropdownlist.

    In either case all this code is doing is setting the selected value on the drop down list on the client side from the passed in Manufacturer value from the Model.

    If you have any other ways to solve this problem please let me know, but this is working for me and hopefully it’ll help someone else with their problem.

    Thank,

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

Sidebar

Related Questions

I have a list view that is displaying data using the gridview. This list
I have a view model with a couple of properties that are not displaying
I have a view that renders a list elements using the following template :
I have an edit view that is displaying some model properties as plain text
I have a View that is displaying data from a list of object that
I have a view that will be displaying downloaded images and text. I'd like
I have table view in that click any i am displaying data in overlay
I have a table view that displays a list that I want the user
I have a view that displays a list of comments. Now a comment can
I have a controller named store_controller.rb and method index that renders index.html.erb , displaying

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.