can not call extension method : error(Public member string on type 'Date' not found. )

0

I've created a extension Method in public Module. when I call it inside the partial View, I encounter the following error: But the program works without calling Toshamsi, and there is no problem Can you give me advice? Where is the problem with this app?

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>

this is module contents:

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

and my 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

asp.net-mvc
vb.net
extension-methods
asked on Stack Overflow Nov 28, 2018 by Ashkan

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0