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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:37:29+00:00 2026-05-11T11:37:29+00:00

The following dropdown does exactly what I want, but I’m looking for a simpler

  • 0

The following dropdown does exactly what I want, but I’m looking for a simpler way to express it (note this is VB syntax).

<%=Html.DropDownList('values', CType(ViewData('values'), IEnumerable(Of SelectListItem)), 'No values', New With {.onchange = 'this.form.submit();'})%> 

Because the ViewData value is named the same as the dropdown, the HTML helper lets the following work:

<%=Html.DropDownList('values', 'No values')%> 

but as soon as I try to add the onchange code:

<%=Html.DropDownList('values', 'No values', New With {.onchange = 'this.form.submit();'})%> 

I get the ‘Overload resolution failed because no accessible ‘DropDownList’ can be called without a narrowing conversion’ error.

How can I take advantage of the HTML helper functionality but still specify htmlAttributes?

  • 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. 2026-05-11T11:37:30+00:00Added an answer on May 11, 2026 at 11:37 am

    EDIT

    Looking at the source code online it appears that, unlike most of the other HtmlHelper extensions, the Select extensions don’t check for null in the values and default to loading based on the model/viewdata. If you don’t want to write your own extension, it appears the best way is to cast the view data as you are doing in your first sample. After checking my own code I find that that is, in fact, what I do.

    Original answer left for context:

    Simply specify the select list as Nothing and it will pull it from your model/viewdata as you expect it. This allows the compiler to match an existing method signature, but doesn’t require that you tell it exactly the list to use. If you look at the source code (www.codeplex.com/aspnet), you’ll see that the methods with fewer parameters do just this sort of substitution, calling the methods with more parameters with suitable defaults.

    <%=Html.DropDownList('values',                      Nothing,                      'No values',                      New With {.onchange = 'this.form.submit();'})%> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the following js works fine in FF2 but in IE6 the dropdown always selects
Following on from this question what would be the best way to write a
Given the following HTML: <select name=my_dropdown id=my_dropdown> <option value=1>displayed text 1</option> </select> How do
Following this question: Good crash reporting library in c# Is there any library like
Following Izb's question about Best binary XML format for JavaME , I'm looking for
Following up on this question, I'm working on a large Delphi 7 codebase which
Following on from the question asked by Mykroft Best way to handle input from
I have the following code which is meant to populate a dropdown with a
Does anyone know how to add an item to a list but do it
I have the following code but I am getting the following compile errors: Attribute

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.