ASP.Net MVC DropDownList With Static values Error: Type expected in VB.Net

Sumeet
 
on Jan 23, 2019 02:29 AM
Sample_208438.zip
1219 Views

Below is my View page code for Html.DropDownList 

  @Html.DropDownList("ddlHospital", New List(Of<SelectListItem>)
                                        {
                                           New SelectListItem { Text = "H1", Value = "1"},
                                           New SelectListItem { Text = "H2", Value = "2"},
                                           New SelectListItem { Text = "H3", Value = "3"},
                                        }, "Select Hospital")

The above code is showing me an error as : Type expected.

on line :

@Html.DropDownList("ddlHospital", New List(Of<SelectListItem>)

Why ?

Using Visual Studio 2017 Community Edition

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jan 23, 2019 03:06 AM

Hi Sumeet,

Check this example. Now please take its reference and correct your code.

Controller

Public Class HomeController
    Inherits System.Web.Mvc.Controller
    ' GET: /Home
    Function Index() As ActionResult
        Return View()
    End Function
End Class

View

<div align="center">
    <%:Html.DropDownList("ddlHospital", New List(Of SelectListItem) From
                                    {
                                        New SelectListItem With {.Text = "H1", .Value = "1"},
                                        New SelectListItem With {.Text = "H2", .Value = "2"},
                                        New SelectListItem With {.Text = "H3", .Value = "3"}
                                    }, "Select Hospital")%>
</div>

Screenshot