1

In my ASP.NET Core MVC project, I have a page where I use DataTables. I added the code to render the table names logs with DataTables.

$(document).ready(function() {
    var logs = $('#logs').dataTable({
        "processing": true,
        "serverSide": true,
        "filter": true,
        "ajax": {
            "url": "/api/logs",
            "type": "POST",
            "dataType": "json"
        },
        "columns": [
            { className: 'dt-control', orderable: false, 
                         data: null, defaultContent: ''},
            { "data": "timeStamp" },
            { "data": "level" },
            { "data": "queueId" },
            { "data": "message" }
        ]
    })
}

The POST API method receives the call from the DataTables for search and order.

var orderColumn = Request.Form["order[0][column]"].FirstOrDefault();
var sortColumnName = "columns[" + orderColumn + "][name]";
var sortColumn = Request.Form[sortColumnName].FirstOrDefault();
var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();
var searchValue = Request.Form["search[value]"].FirstOrDefault();

When I order for the column number 5, the sortColumnName tries to read from the RequestForm this column but the value is empty.

enter image description here

I don't understand why.

1 Answer 1

1

I had this once, and it was because of the max length or one such property on kestrel. I'm not sure which one so might as well try all of them.

Here's how to configure all of the relevant options:

Form options:

builder.Services.Configure<FormOptions>(options =>
{
    options.MultipartBodyLengthLimit = 104857600; // 100 MB
    options.ValueLengthLimit = int.MaxValue;
    options.KeyLengthLimit = int.MaxValue;
    options.MultipartHeadersLengthLimit = int.MaxValue;
});

Max request body size:

builder.WebHost.ConfigureKestrel(serverOptions =>
{
    serverOptions.Limits.MaxRequestBodySize = 104857600; // 100 MB
});

You can also use the attribute only for that action if this is the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.