невозможно вызвать метод расширения: ошибка (открытая строка с типом «Дата» не найдена.) - PullRequest
0 голосов
/ 28 ноября 2018

Я создал метод расширения в публичном модуле.когда я вызываю его в частичном представлении, я сталкиваюсь со следующей ошибкой: но программа работает без вызова 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

и мой частичный просмотр:

@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
...