如何在 vb.net 中与服务器端进行可引导



我使用来自 datatable.net 的compoment

我看到了很多示例 en c#...但我在 vb.net 翻译没有成功。 我从 datatable.net 的样本中看,这个 但是我有错误消息说

数据表警告无效的 json 响应...

我的 aspx 页

<asp:Content ID="Content2" ContentPlaceHolderID="CPLContent" runat="Server">
<div class="container-fluid">
    <div class="row">
        <div class="panel panel-default " id="panBeneficiaireListe" runat="server">
            <div class="panel-heading">
                <h3 class="panel-title">Bénéficiaires</h3>
                <ul class="list-inline panel-actions">
                    <li><a href="#" id="panel-fullscreen" role="button" title="Toggle fullscreen"><i class="glyphicon glyphicon-resize-full panel-fullscreen-button"></i></a></li>
                </ul>
            </div>
            <div class="panel-body">
                <table class="table" id="LBENEF">
                    <thead>
                        <tr>
                            <td></td>
                            <td>Actif</td>
                            <td>Type</td>
                            <td>Identifiant</td>
                            <td>Nom</td>
                            <td>Site</td>
                            <td>Perimètre</td>
                            <td class="col40px"></td>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>
<script>
    $('#LBENEF').DataTable({
        stateSave: true,
        bServerSide: true,
        bProcessing: true,
        sAjaxSource: document.location.pathname + '/GetInfo'
    });
  </script>
</asp:Content>

还有我的aspx.vb

Imports System.Web.Script.Serialization
Imports System.Web.Script.Services
Imports System.Web.Services
Imports WPM_DATA.V15.SecuriteQueries
Partial Class Beneficiaire_List
Inherits pageBase

<WebMethod(EnableSession:=True)>
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)>
Public Shared Function GetInfo() As String
    Dim echo = Integer.Parse(HttpContext.Current.Request.Params("sEcho"))
    Dim displayLength = Integer.Parse(HttpContext.Current.Request.Params("iDisplayLength"))
    Dim displayStart = Integer.Parse(HttpContext.Current.Request.Params("iDisplayStart"))
    Dim search As String = HttpContext.Current.Request.Params("sSearch")
    Dim datacontext As New WPM15_Entities
    Dim userQuery As New ConnectedUserQueries(datacontext)
    Dim records = userQuery.BeneficiairesAffectes()
    If (Not records.Any()) Then
        Return String.Empty
    Else
        Dim itemsToSkip As Integer = If(displayStart = 0, 0, displayStart + 1)
        Dim pagedResults = records.Skip(itemsToSkip).Take(displayLength).ToList()
        Dim result = New With {
             Key .iTotalRecords = records.Count,
             Key .iTotalDisplayRecords = records.Count,
             Key .aaData = pagedResults
        }
        Dim js As New JavaScriptSerializer()
        Return js.Serialize(result)
    End If
End Function
End Class

我在GetInfo的启动中在我的可视化工作室上放置了一个断点,但我没有达到它。 如果有人有 vb.net 的例子可以给出或可以帮助我纠正哑剧......

我更改了我的js代码

  $('#LBENEF').DataTable({
        stateSave: true,
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "/Beneficiaire/list.aspx/GetInfo",
        "fnServerData": function (sSource, aoData, fnCallback) {
            
            $.ajax({
                "dataType": 'json',
                "contentType": "application/json; charset=utf-8",
                "type": "GET",
                "url": sSource,
                "data": aoData,
                "success": function (msg) {
                    var json = jQuery.parseJSON(msg.d);
                    fnCallback(json);
                    $("#tblData").show();
                },
                error: function (xhr, textStatus, error) {
                    if (typeof console == "object") {
                        console.log(xhr.status + "," + xhr.responseText + "," + textStatus + "," + error);
                    }
                }
            });
        },
        fnDrawCallback: function () {
            //$('.image-details').bind("click", showDetails);
        }
    });

我忘记了在vb中"UseHttpGet:=True"而不是UseHttpGet:=False :-(

更新

这很好,但对于传统模式(在我忘记数据属性中的 aoData 之前(

对于正常模式...

 $('#LBENEF').DataTable({
        "processing": true,
        "serverSide": true,
        "ajax": "/Beneficiaire/ListBeneficiaires.asmx/GetListBenef"
    });

我忘了我有一个母版页,当你在 aspx 中使用网络方法时,你会在到达你的网络方法之前加载你的部分响应中的母版......然后需要通过ASMX(或ASXX...任何依赖于母版页的内容(

更新 2

不要像这里这样改变你的 web.config 来让 web 服务中的 get 方法

<webServices>
        <protocols>
            <add name="HttpGet"/>
        </protocols>
    </webServices>

最新更新