2012-01-12 28 views
0

我使用C#完成了下面的web方法。我試着將它轉換成VB.NET,但我錯過了一些東西。我用一個pajaator/sorter表插件來調用ajax。將c#的webmethod轉換爲vb.net

[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 }; 
} 

首先,在VB錯誤 - 我不能離開參數作爲任選(「屬性的WebMethod不能應用於方法使用可選參數」):

<WebMethod()> _ 
Public Function listaPessoas(Optional ByVal jtStartIndex As Integer = 0, 
          Optional ByVal jtPageSize As Integer = 0, 
          Optional ByVal jtSorting As String = Nothing) 

其次,我不知道如何返回消息「OK」和人員列表。

任何人都可以幫我把它轉換成VB.NET嗎?

+0

您是否嘗試刪除'optional'並聲明webmethod屬性'?如果您需要可選參數,則應該重載該方法。 – 2012-01-12 14:16:31

回答

1

好像你不能在WebMethods中使用可選參數。你可以使用重載。例如:

<WebMethod()> _ 
Public Function listaPessoas(jtStartIndex As Integer, jtPageSize As Integer) 

<WebMethod()> _ 
Public Function listaPessoas(jtStartIndex As Integer, jtPageSize As Integer, jtSorting As String) 

返回的C#對象是一個匿名對象。 VB的語法是:

Return New With { .Result = "OK", 
        .Records = persons.ToList(), 
        .TotalRecordCount = persons.count }