无法调用扩展方法:错误(找不到类型为“日期”的公共成员字符串。)

时间:2018-11-28 06:23:16

标签: asp.net-mvc vb.net extension-methods

我已经在公共模块中创建了一个扩展方法。 当我在局部视图中调用它时,遇到以下错误: 但是该程序无需调用Toshamsi就可以运行,并且没有问题 你能给我建议吗? 这个应用程式在哪里出问题?

System.MissingMemberException
  HResult=0x80131512
  Message=Public member 'ToShamsi' on type 'Date' not found.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

这是模块内容:

Imports System.Runtime.CompilerServices
Imports System.Globalization
Public Module StringExtensions
    <Extension()>
    Public Function ToShamsi(ByVal value As Date) As String
        Dim pc As New PersianCalendar
        Return pc.GetYear(value).ToString + "/" + pc.GetMonth(value).ToString("00") + "/" + pc.GetDayOfMonth(value).ToString("00")
    End Function

    <Extension()>
    Public Function ToMiladi(ByVal value As String) As Date


        Dim p As New System.Globalization.PersianCalendar

            Dim yy As String = Mid(value, 1, 4)
            Dim mm As String = Mid(value, 6, 2)
            Dim dd As String = Mid(value, 9, 2)

            Return p.ToDateTime(yy, mm, dd, 0, 0, 0, 0, 0)

    End Function

End Module

和我的Partialview:

@ModelType IEnumerable(Of Machinary.InsProvider)
@Code
    Dim wg As New WebGrid(Model, rowsPerPage:=10, canPage:=True, canSort:=True, ajaxUpdateContainerId:="wg1")
    Dim rowIndex = ((wg.PageIndex + 1) * wg.RowsPerPage) - (wg.RowsPerPage - 1)
End Code

@wg.GetHtml(tableStyle:="table table-bordered table-hovor", mode:=WebGridPagerModes.All,
                                                htmlAttributes:=New With {.id = "wg1", .class = "Grid"},
                                                firstText:="<<",
                                                lastText:=">>",
                                                footerStyle:="table-pager",
                                                columns:=wg.Columns(
                                                wg.Column("InsNo", Sorter("InsNo", "شماره بیمه نامه", wg)),
                                                wg.Column("ProviderName", Sorter("ProviderName", "نام بیمه گر", wg)),
                                                wg.Column("StartDate", Sorter("StartDate", "تاریخ شروع", wg), format:=Function(item) item.StartDate.ToShamsi),
                                                wg.Column("EndDate", Sorter("EndDate", "تاریخ پایان", wg)),
                                                wg.Column("Email", Sorter("Email", "ایمیل", wg)),
                                                wg.Column(header:="عملیات", format:=Function(item) New HtmlString(
                                                Html.ActionLink(" ", "InsProviderEdit", New With {.id = item.id}, htmlAttributes:=New With {.class = "glyphicon glyphicon-edit btn btn-info btn-sm", .data_toggle = "tooltip", .data_placement = "top", .title = "ویرایش"}).ToString() + " " +
                                                Html.ActionLink(" ", "InsProviderDelete", New With {.id = item.id}, htmlAttributes:=New With {.class = "glyphicon glyphicon-trash btn btn-danger btn-sm", .data_toggle = "tooltip", .data_placement = "top", .title = "حذف"}).ToString()))))


@functions
    Public Shared Function Sorter(columnName As String, columnHeader As String, grid As WebGrid) As String
    Return String.Format("{0} {1}", columnHeader, If(grid.SortColumn = columnName, If(grid.SortDirection = SortDirection.Ascending, "▲", "▼"), String.Empty))
End Function
End Functions

0 个答案:

没有答案