Asp.Net MVC 5 VB Error : " error BC36604: Late binding operations cannot be converted to an expression tree"

So I'm trying to pass data from a database into a drop down list on a site I'm making for an internship project. I have the LINQ query working and everything, I just don't get what the error is caused by or how to fix it. Any help would be appreciated.

Here is the code with the query from my controller for the page
Public Function gasrevperyearDD() As IEnumerable(Of SelectListItem)

            Dim List As New List(Of SelectListItem)
            List.Add(New SelectListItem With {.Text = "Select a Year", .Value = 0}) ' Adds first value as "Select a Year"
            Dim valQ = From y In db.gasrevperyears _
                      Select y.year, y.ID _
                      Order By year

            For Each k In valQ
                List.Add(New SelectListItem With {.Text = k.year, .Value = k.ID})
            Next
            gasrevperyearDD = List
        End Function

Open in new window



Here is my code from the view

@Html.DropDownListFor(Function(m) m.gasrevperyear, DirectCast (ViewData("gasrevperyearDD"), IEnumerable(Of SelectListItem)))

Open in new window

shanker702Asked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
Can you show your page directive from the top of razor page?
0
 
shanker702Author Commented:
I don't have one I think, would it be at the top of the view file for the page?
0
 
CodeCruiserCommented:
Yes
0
 
käµfm³d 👽Commented:
What does the assignment to gasrevperyear look like?
0
 
shanker702Author Commented:
Got me in the right direction and I figured it out. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.