ASP.NET Web API 2とjQuery Datatables 1.10.7を統合しようとしています。ここでjQuery Datatables Web APIに正しくアクセスしないAJAXリクエスト
を、私は私のDataTableの中にサーバー側の処理を使用したいので、私はDataTables.AspNet.WebApi2 Nugetパッケージを使用しています
は私のjavascriptが
ある<script>
$(document).ready(function() {
$('#example').dataTable({
"serverSide": true,
"ajax": "/api/StudentsBasicInfo/GetPaginatedStudentsList2",
columns: [
{
name: 'FirstName',
data: 'FirstName',
title: "First Name",
sortable: false,
searchable: false
},
{
name: 'LastName',
data: "LastName",
title: "Last Name",
sortable: false,
searchable: false
}
]
});
});
</script>
ここに私のHTMLは
です<table id="example" class="display" cellspacing="0" width="100%">
</table>
ここは自分のWeb APIです
public JsonResult<IDataTablesResponse> GetPaginatedStudentsList2(IDataTablesRequest request)
{
StudentsInfoHybrid searchObj = new StudentsInfoHybrid();
StudentsBasicInfoBL blClass = new StudentsBasicInfoBL();
try
{
searchObj.PageSize = request.Length;
searchObj.Offset = request.Start;
searchObj.count = false;
//get the list of students
var students = blClass.GetAllStudentsHybridInfo(searchObj);
//filter list according to the criteria passed in the request object
var filteredStudents = students.Where(i => i.FirstName.Contains(request.Search.Value)).ToList();
//reset page size and offset so that count of total objects can be obtained
searchObj.PageSize = 0;
searchObj.Offset = 0;
var totalCount = blClass.CountAllStudentsHybridInfo(searchObj);
var response = DataTablesResponse.Create(request, students.Count(), filteredStudents.Count(), filteredStudents);
return new DataTablesJsonResult(response, Request);
}
catch (Exception ex)
{
return null;
}
finally
{ }
}
私のコードは完璧に構築しますが、データテーブルのコールのWeb APIは、私はIDataTablesRequest要求オブジェクトがnullでデバッグモードで見ることができます実行中。
次はGoogle Chromeネットワークログのスクリーンショットです。
私はネットワークログから見ることができるように、ウェブAPIは、私がおよそ見当もつかないこの例外を返しています。
私のリクエストがGoogle Chromeのネットワークログのように見える別のスクリーンショットも添付しています。あなたが何かを送信していないwebapi
にAJAX呼び出しを送信している間