Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 2309ec3

Browse files
committed
Added sample to return data as Json
Removed namespaces from sample code and added sample returning Json data.
1 parent db472d9 commit 2309ec3

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@
2121
</p>
2222

2323
```C#
24-
public ActionResult MyActionResult([ModelBinder(typeof(DataTables.Mvc.DataTablesBinder)] IDataTablesRequest requestModel)
24+
public ActionResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTablesRequest requestModel)
2525
{
2626
// do your stuff...
27-
return new DataTablesResponse(requestModel.Draw, myFilteredData.Skip(requestModel.Start).Take(requestModel.Length), myFilteredData.Count(), myOriginalDataSet.Count());
27+
var paged = myFilteredData.Skip(requestModel.Start).Take(requestModel.Length);
28+
return new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count());
29+
}
30+
31+
// Or if you'd like to return a JsonResult, try this:
32+
33+
public JsonResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTablesRequest requestModel)
34+
{
35+
// do your stuff...
36+
var paged = myFilteredData.Skip(requestModel.Start).Take(requestModel.Length);
37+
return Json(new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count()));
2838
}
2939
```
3040
<h3>Any gotchas?</h3>

0 commit comments

Comments
 (0)