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 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

Following dropdown: <select id='dropdown' name='dropdown' onchange='showChart(this.value)'> <option value=1>Foo</value> <option value=2>Bar</value> </select> Calls this javascript
The following dropdown menu works fine in modern browsers (IE7/firefox) but not in IE6.
if i have a dropdown with the following html: <select id=myDropdown name=myDropdown> <option value=6>Six</option>
I want to do the following: 1: Add two dropdown list in the register.aspx
I have following asp.net code but it gives error when I change dropdown selected
Consider the following HTML snippet. The desired effect is to have a dropdown be
I want to create a script that does the following: When answering questions via
I have a dropdown box and a text box. I searched this site but
Note: my application is way more complicated but I'm stripping anything that is not
I was following a dropdown menu tutorial: http://net.tutsplus.com/tutorials/html-css-techniques/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:%20nettuts%20(NETTUTS)&utm_content=Netvibes What I really want to do

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.