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

Commit

Permalink
Added sample to return data as Json
Browse files Browse the repository at this point in the history
Removed namespaces from sample code and added sample returning Json
data.
  • Loading branch information
ALMMa committed Mar 20, 2014
1 parent db472d9 commit 2309ec3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@
</p>

```C#
public ActionResult MyActionResult([ModelBinder(typeof(DataTables.Mvc.DataTablesBinder)] IDataTablesRequest requestModel)
public ActionResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTablesRequest requestModel)
{
// do your stuff...
return new DataTablesResponse(requestModel.Draw, myFilteredData.Skip(requestModel.Start).Take(requestModel.Length), myFilteredData.Count(), myOriginalDataSet.Count());
var paged = myFilteredData.Skip(requestModel.Start).Take(requestModel.Length);
return new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count());
}

// Or if you'd like to return a JsonResult, try this:
public JsonResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTablesRequest requestModel)
{
// do your stuff...
var paged = myFilteredData.Skip(requestModel.Start).Take(requestModel.Length);
return Json(new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count()));
}
```
<h3>Any gotchas?</h3>
Expand Down

0 comments on commit 2309ec3

Please sign in to comment.