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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:33:17+00:00 2026-06-10T03:33:17+00:00

In my controller, I have defined the select list items and the passed the

  • 0

In my controller, I have defined the select list items and the passed the list to the view as

Dim mySelectItems = New List(Of SelectListItem) From {
    New SelectListItem With {.Text = "First item", .Value = "1", .Selected = True}
}

ViewData("doctorList") = mySelectItems

Now, from my view, I am trying to feed the values into a DropDown List using the HTML Helper.

<label for="appointment_doctor">Select Doctor</label>
<%= Html.DropDownList("doctor", ViewData("doctorList"))%>

Now, I am thinking this should work but it is not.

Error Log:

Overload resolution failed because no accessible ‘DropDownList’ can be
called without a narrowing conversion:
Extension method ‘Public Function DropDownList(name As String, selectList As System.Collections.Generic.IEnumerable(Of
System.Web.Mvc.SelectListItem)) As System.Web.Mvc.MvcHtmlString’
defined in ‘System.Web.Mvc.Html.SelectExtensions’: Argument matching
parameter ‘selectList’ narrows from ‘Object’ to
‘System.Collections.Generic.IEnumerable(Of
System.Web.Mvc.SelectListItem)’.
Extension method ‘Public Function DropDownList(name As String, optionLabel As String) As System.Web.Mvc.MvcHtmlString’ defined in
‘System.Web.Mvc.Html.SelectExtensions’: Argument matching parameter
‘optionLabel’ narrows from ‘Object’ to
‘String’. G:\Surgery\Surgery\Views\Appointment\Index.aspx 11 13 Surgery

  • 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-06-10T03:33:19+00:00Added an answer on June 10, 2026 at 3:33 am

    Try casting:

    <%= Html.DropDownList(
        "doctor", 
        CType(ViewData("doctorList"), IEnumerable(Of SelectListItem)) 
    ) %>
    

    The cast is necessary because ViewBag is a dynamic type and extension methods (such as DropDownList) cannot be dispatched with dynamic parameters.

    And by the way that’s one of the millions of reasons why I prefer using a view model instead of ViewBag. It also allows you to use the strongly typed version of the helper:

    <%= Html.DropDownList(
        Function(x) x.SelectedDoctorId, 
        Model.Doctors 
    ) %>
    

    UPDATE:

    As requested in the comments section here’s a full example using a view model.

    As always in an ASP.NET MVC application we start by defining our view model class that will reflect the requirements of your view which from your description so far I understood that it should display a dropdown list of doctors. You might will obviously need to enrich this view model with other properties in order to reflect your specific view requirements:

    Public Class DoctorViewModel
        Property SelectedDoctorId As Integer
        Property Doctors As IEnumerable(Of SelectListItem)
    End Class
    

    then you could have a controller action that will populate this view model and pass it to the view:

    Public Class HomeController
        Inherits System.Web.Mvc.Controller
    
        Function Index() As ActionResult
            Dim model = New DoctorViewModel()
    
            ' TODO: those could come from a database or something
            ' I am hardcoding the values here for better understanding
            model.Doctors = {
                New SelectListItem With {.Value = "1", .Text = "doctor 1"},
                New SelectListItem With {.Value = "2", .Text = "doctor 2"},
                New SelectListItem With {.Value = "3", .Text = "doctor 3"}
            }
    
            Return View(model)
        End Function
    End Class
    

    and finally you will have a corresponding strongly typed view (~/Views/Home/Index.aspx):

    <%@ Page 
        Language="VB" 
        MasterPageFile="~/Views/Shared/Site.Master" 
        Inherits="System.Web.Mvc.ViewPage(Of ToDD.DoctorViewModel)" %>
    
    <asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
        Home Page
    </asp:Content>
    
    <asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    
        <%= Html.DropDownListFor(Function(x) x.SelectedDoctorId, Model.Doctors) %>
    
    </asp:Content>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable @products = Product.all defined inside new method in a controller.
I have 2 view controllers. In the first I select a categorie in a
I have a Controller named Author . Inside the controller, I have defined a
I have a controller defined as: [AcceptVerbs(HttpVerbs.Post)] public JsonResult PostMoreData(DataContracts.Address address, DataContracts.GeoLocation geoLocation) {
I have a Controller defined like this: package controllers import play.api._ import play.api.mvc._ import
I have an ASP.NET MVC 3 controller action. That action is defined as follows:
First of all i am brand new to Java : / I have been
I'm trying to put an image in view section I have defined a table
I have created a small table view(no scroll) and want the user to select
Most of the actions in my controller have statically-defined parameter lists and so they

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.