Skip to content

Instantly share code, notes, and snippets.

@ChaosEngine
Created August 31, 2017 22:51

Revisions

  1. ChaosEngine created this gist Aug 31, 2017.
    30 changes: 30 additions & 0 deletions Ajax-Datatable.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    [HttpGet]
    public async Task<IActionResult> Load(string sort, string order, string search, int limit, int offset, string extraParam)
    {
    CancellationToken token = HttpContext.RequestAborted;
    try
    {
    var found = await _repo.SearchAsync(sort, order, search, offset, limit, token);

    var result = new
    {
    total = found.Count,
    rows = found.Itemz
    };

    var content = JsonConvert.SerializeObject(result, Formatting.None,
    new JsonSerializerSettings() { MetadataPropertyHandling = MetadataPropertyHandling.Ignore });

    return Content(content, "application/json");
    }
    catch (OperationCanceledException ex)
    {
    _logger.LogError(ex, $"Cancelled {nameof(Load)}::{nameof(_repo.SearchAsync)}({sort}, {order}, {search}, {offset}, {limit}, {token})");
    return Ok();
    }
    catch (Exception ex)
    {
    _logger.LogError(ex, $"{nameof(Load)}::{nameof(_repo.SearchAsync)}({sort}, {order}, {search}, {offset}, {limit}, {token})");
    throw;
    }
    }