Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net core 2.0 JsonDataTable ? #22

Closed
ghost opened this issue Jul 4, 2018 · 3 comments
Closed

.net core 2.0 JsonDataTable ? #22

ghost opened this issue Jul 4, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 4, 2018

returning JsonDataTable doesn't work in .net core any workaround?

@sebastianbk
Copy link

Here is what I did. I created this method in the bottom of my controller:

private JsonResult GenerateDataTableResponse<T>(int draw, IPagedList<T> model)
{
    return new JsonResult(new
    {
        draw = draw,
        recordsTotal = model.TotalCount,
        recordsFiltered = model.TotalCount,
        data = model
    });
}

Then I made my actions like this:

[Produces("application/json")]
[HttpGet("{id}/entries")]
public async Task<IActionResult> Entries(Guid id, [FromQuery(Name = "draw")] int draw)
{
    // Getting my entries. The variable entries is an instance of IQueryable<T> where T in my case is EntryViewModel.

    var request = new DataTablesRequest<EntryViewModel>(Request.QueryString.ToString());
    var filtered = entryViewModels.ToPagedList(request);
    return GenerateDataTableResponse(draw, filtered);
}

@sebastianbk
Copy link

By the way, if you would like a .NET Core-compatible version of the library you should checkout this NuGet package: https://github.com/sebastianbk/DataTables.Queryable.Core

@AlexanderKrutov
Copy link
Owner

Latest versions (since 1.7.0) of the library support .Net Core 2.0. Please check the: https://www.nuget.org/packages/DataTables.Queryable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants