Over the weekend, I ran into a strange problem when I was working on the asp.net mvc project on vb.net. I created an extension method to convert an integer to the corresponding month with which it is associated. I tested the extension method in a console application, so I know that it works.
In my asp.net mvc project, I have a view and you want to call the extension method, but I get an error that the extension method is not recognized. I imported the namespace in which it was contained, and still cannot shake the error. Any idea what is going on? I don't have my code, but I can post it tonight if that helps. Thanks!
Extension Method:
Imports System.Runtime.CompilerServices
Module SiteExtensions
<Extension()> _
Public Function ConvertToMonth(ByVal monthNumber As Integer) As String
Dim month As String = String.Empty
Select Case monthNumber
Case 1
month = "January"
Case 2
month = "February"
Case 3
month = "March"
Case 4
month = "April"
Case 5
month = "May"
Case 6
month = "June"
Case 7
month = "July"
Case 8
month = "August"
Case 9
month = "September"
Case 10
month = "October"
Case 11
month = "November"
Case 12
month = "December"
End Select
Return month
End Function
End Module
View:
<% For Each m As Integer In DirectCast(ViewData("Months"), IEnumerable)%>
<a href="#"><%=m.ConvertToMonth()%><br /></a>
<%Next%>
: "ConvertToMonth Integer"