如何在vb.net中创建服务器端的数据引导程序

时间:2018-04-30 10:00:38

标签: asp.net vb.net visual-studio datatable server-side

我使用datatable.net

中的组件

我看到很多样本#...但我在vb.net中翻译没有成功。 我从Sample from datatable.netthis on开始查看 但我的错误信息是

  

数据表警告无效的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中有一个例子可以帮助我修改哑剧...

1 个答案:

答案 0 :(得分:0)

我改变了我的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"
    });

我忘记了我有一个masterPage,当你在aspx中使用webmethod时,你会在你的webmethod之前加载你的主人的部分响应...然后需要通过asmx(或者ashx ...任何依赖于主页)

更新2

不要改变你的web.config来让web服务中的get方法如说here

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