Hello,
I am migrating an application that is in Net framework to .Net6 the application with Net Framework works well for me, when executing the application it brings me all the data and I show it in a table. For this I am using jquery-3.5.1.js and jquery.dataTables.min.js in the front and for the back I use DataTable.Mvc
There I show my function that is executed when the page loads and fills a DataTable with the data.
The problem is in .Net6, the request does not work for me, in the frontend I am using jquery-3.5.1.js and jquery.dataTables.min.js and for the back I use DataTables.AspNet.AspNetCore
This line of code is not working "[ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel", DataTablesBinder is not found in the package I installed.
I hope you can help me to solve the problem. Thank you.
<div class="box-header">
<a href="#collapsibleList" data-toggle="collapse" class="h4 text-decoration-none">List transactions</a>
</div>
<table id="tableList">
</table>
<div class="btn btn-primary" role="button" id="btnFilter">Filter</div>
<script src="~/Datatables/datatables.min.js"></script>
<script src="~/Datatables/dataTables.bootstrap.min.js"></script>
<script src="~/Datatables/datatables.cache.js"></script>
<script>
var table;
var filterOptions = {
dni: '0',
StartDate: ''}
$(document).ready(function () {
('#btnFilter').on('click', function (e) {
var dni = $('#txtRut').val().replaceAll('.', '').split('-')[0];
var StartDate = $('#StartDate').val() != '' ? moment($('#StartDate').datepicker('getDate')).toISOString() : undefined;
applyFilter(dni, StartDate);
$('#collapsibleList').collapse('show');
// ir a mostrar la lista de transacciones
$([document.documentElement, document.body]).animate({
scrollTop: $("#collapsibleList").offset().top
}, 1300);
});
table = setupDatatable();
}
function applyFilter(dni, StartDate) {
filterOptions.dni = dni;
filterOptions.StartDate = StartDate;
if (table !== undefined) {
table.clearPipeline();
table.draw();
}
}
function setupDatatable() {
var dtOptions = {
serverSide: true,
processing: true,
ajax: $.fn.dataTable.pipeline({
pages: 10,
url: '@Url.Action("NameMethod", "NameController")',
method: 'POST',
data: function (d) {
d.filtroTC = filterOptions;
},
error: function (data) {
console.log(data);
$.dataTableErrorHandler(data, null, 'tablaListaTXTC');
}
}),
deferLoading: 0,
select: {
style: 'os',
},
lengthMenu: [10, 25, 50, 75, 100, 125, 150],
pageLength: 50,
searching: false,
scrollX: true,
order: [[0, 'desc']],
columns: [
{
title: 'Dni',
data: 'dni',
},
{
title: 'Start Date',
data: 'start_date',
}
],
};
table = $('#tableList').DataTable(dtOptions);
return table;
}
</script>
[HttpPost]
public JsonResult NameMethod(Filter filter,
[ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel
)
{
/*All the rest code*/
}