【发布时间】:2010-10-27 00:33:57
【问题描述】:
周末我在 vb.net 中处理 asp.net mvc 项目时遇到了一个奇怪的问题。我创建了一个扩展方法来将整数转换为与之关联的相应月份。我在控制台应用程序中测试了扩展方法,所以我知道它正在工作。
在我的 asp.net mvc 项目中,我有一个视图并想调用扩展方法,但我收到扩展方法无法识别的错误。我导入了它包含的名称空间,但仍然无法摆脱错误。知道发生了什么吗?我没有我的代码,但如果有帮助,我可以在今晚发布。谢谢!
扩展方法:
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
查看:
<% For Each m As Integer In DirectCast(ViewData("Months"), IEnumerable)%>
<a href="#"><%=m.ConvertToMonth()%><br /></a>
<%Next%>
错误是:“ConvertToMonth 不是 Integer 的成员”
乔恩
【问题讨论】:
标签: asp.net-mvc vb.net .net-3.5 extension-methods