I did the web method below using C#. I’m tryin to convert this into VB.NET, but I’m missing something. I’m using it with an ajax calling, from a paginator/sorter table plugin.
[WebMethod( EnableSession = true )]
public static object listaPessoas(int jtStartIndex = 0,
int jtPageSize = 0,
string jtSorting = null)
{
return new { Result = "OK",
Records = persons.ToList(),
TotalRecordCount = persons.count };
}
First, error in VB – I can’t leave the parameters as optional(“Attribute WebMethod cannot be applied to a method with optional parameters“):
<WebMethod()> _
Public Function listaPessoas(Optional ByVal jtStartIndex As Integer = 0,
Optional ByVal jtPageSize As Integer = 0,
Optional ByVal jtSorting As String = Nothing)
Second, I don’t know how to return the message “OK” and the list of people.
Can anyone me help to convert this into VB.NET?
Seems like you can’t use optional parameters with WebMethods. You can use overloading. Example:
The C# object returned is an anonymous object. The VB syntax is: