🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)
🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 19 Min Lesezeit
0

ASP.NET8 using DataTables.net – Part1 – Foundation

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

A practical guide to using jQuery DataTables.net component in Asp.Net 8 MVC application.



Abstract: A practical guide to building an Asp.Net 8 MVC application that uses jQuery component DataTables.net. The article focuses on integrating different technologies (ASP.Net8, MVC, C#, Bootstrap 5, jQuery DataTables.net) into a professional-level application.






1 ASP.NET8 using jQuery DataTables.net



I was searching for a freeware table component that would fit into my developing environment for my new project, which is ASP.NET8, C#, MVC, Bootstrap 5, EF. In a number of places, I saw mention of the jQuery DataTables.net component [1]. After shortly looking into different articles, I decided to create several prototype (proof-of-concept) applications to evaluate it for usage in my professional projects. These articles are the result of that evaluation.






1.1 Articles in this series



Articles in this series are:




  • ASP.NET8 using DataTables.net – Part1 – Foundation

  • ASP.NET8 using DataTables.net – Part2 – Action buttons

  • ASP.NET8 using DataTables.net – Part3 – State saving

  • ASP.NET8 using DataTables.net – Part4 – Multilingual

  • ASP.NET8 using DataTables.net – Part5 – Passing additional parameters in AJAX

  • ASP.NET8 using DataTables.net – Part6 – Returning additional parameters in AJAX

  • ASP.NET8 using DataTables.net – Part7 – Buttons regular

  • ASP.NET8 using DataTables.net – Part8 – Select rows

  • ASP.NET8 using DataTables.net – Part9 – Advanced Filters






2 Final result



Let us present the result of this article prototyping in ASP.NET8, C#, MVC, Bootstrap 5 environment. Here is what you get:







I of course extracted only relevant data parts. Every better Web programmer should be able to understand what is going on from the above data.






8 DataTables.AspNet.Core library



If you are ASP.NET back-end programmer, the question from the above sample AJAX call is how to parse all that data input on the server side.



The answer is, I am using DataTables.AspNet.Core library [2], [3]. That library is both a solution and a problem. It provides useful utility freely available but is no longer maintained since 2022. My thinking is, that if I do not use that library, I will need to write my own version of the same, probably coming to very similar design solutions. So, I decided to use it and patch it when needed.



How do you learn that library? There are no tutorials available. So, I just downloaded the source code from GitHub and learned it from the source code. There are also some examples available as demos at the same site.



From now on, I will just be using that library in my code in this article.






9 System.Linq.Dynamic.Core library



There is another library that is useful for back-end processing in this application, that is System.Linq.Dynamic.Core library [12]-[14]. There is a nice tutorial available at [14]. From now on, I will just be using that library in my code in this article.






10 ASP.NET back-end processing



So, we are now at C#/.NET part, writing our ASP.NET code. Here is the solution I came up with. I will not pretend it is easy, it assumes a good understanding of libraries DataTables.AspNet.Core and System.Linq.Dynamic.Core. I exploit those libraries and LINQ to solve the problem.



I was going for a generic solution and reusable code. Otherwise, for each table, I would need to again write filter and sort methods specifically tailored to each new entity.



Here is the code:




CODE
//HomeController.cs ======================================

//this is target of AJAX call and provides data for
//the table, based on selected input parameters
public IActionResult EmployeesDT(DataTables.AspNet.Core.IDataTablesRequest request)
{
// There is dependency in this method on names of fields
// and implied mapping. I see it almost impossible to avoid.
// At least, in this method, we avoided dependency on the order
// of table fields, in case order needs to be changed
//Here are our mapped table columns:
//Column0 id -> Employee.Id
//Column1 givenName -> Employee.FirstName
//Column2 familyName -> Employee.LastName
//Column3 town -> Employee.City
//Column4 country -> Employee.Country
//Column5 email -> Employee.Email
//Column6 phoneNo -> Employee.Phone

try
{
IQueryable<Employee> employees = MockDatabase.MockDatabase.Instance.EmployeesTable.AsQueryable();

//here we get the count that needs to be presented by the UI
int totalRecordsCount = employees.Count();

var iQueryableOfAnonymous = employees.Select(p => new
{
id = p.Id,
givenName = p.FirstName,
familyName = p.LastName,
town = p.City,
country = p.Country,
email = p.Email,
phoneNo = p.Phone,
});

iQueryableOfAnonymous = FilterRowsPerRequestParameters(iQueryableOfAnonymous, request);

//here we get the count that needs to be presented by the UI
int filteredRecordsCount = iQueryableOfAnonymous.Count();

iQueryableOfAnonymous = SortRowsPerRequestParamters(iQueryableOfAnonymous, request);

iQueryableOfAnonymous = iQueryableOfAnonymous.Skip(request.Start).Take(request.Length);

//here we materialize the query
var dataPage = iQueryableOfAnonymous.ToList();

var response = DataTablesResponse.Create(request, totalRecordsCount, filteredRecordsCount, dataPage);

return new DataTablesJsonResult(response, false);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
var response = DataTablesResponse.Create(request, "Error processing AJAX call on server side");
return new DataTablesJsonResult(response, false);
}
}

private IQueryable<T> SortRowsPerRequestParamters<T>(
IQueryable<T> iQueryableOfAnonymous, DataTables.AspNet.Core.IDataTablesRequest request)
{
/*
* So, in "IQueryable<T> iQueryableOfAnonymous" I have the source data that I need to
* sort. In "DataTables.AspNet.Core.IDataTablesRequest request" I have full specification
* of sorting required, including the specification of columns
* that need to be sorted by marked with "IsSortable" and "Sort.Order".
* I use Reflection to check if names of entity T properties match column names in
* DataTables.AspNet.Core.IDataTablesRequest request and then create sort Linq query using
* System.Linq.Dynamic.Core library, and return Linq query as a result.
* It might look complicated, but advantage is that this method is generic and can
* be applied many times on different entities T.
*/


if (request != null && request.Columns != null && request.Columns.Any())
{
//this will work if type T contains properties that have names column.Name
var sortingColumns = request.Columns.Where(p => p.IsSortable && p.Sort != null).OrderBy(p => p.Sort.Order).ToList();

Type objType = typeof(T);
var ListOfAllPropertiesInT = objType.GetProperties().Select(p => p.Name).ToList();

if (sortingColumns != null && sortingColumns.Count > 0)
{
//we plan to build dynamic Linq expression in this string
string dynamicLinqOrder = string.Empty;
bool isFirstString = true;

for (int i = 0; i < sortingColumns.Count; i++)
{
var column = sortingColumns[i];

//check if that property exists in T,
//otherwise we will create syntax error in dynamic linq
if (ListOfAllPropertiesInT.Contains(column.Name))
{
if (isFirstString)
{
isFirstString = false;
}
else
{
dynamicLinqOrder += ", ";
}

dynamicLinqOrder += column.Name;
if (column.Sort.Direction == SortDirection.Descending)
{
dynamicLinqOrder += " desc";
}
}
}

if (dynamicLinqOrder.Length > 0)
{
//using System.Linq.Dynamic.Core
iQueryableOfAnonymous = iQueryableOfAnonymous.OrderBy(dynamicLinqOrder);
}
};
}

return iQueryableOfAnonymous;
}

private IQueryable<T> FilterRowsPerRequestParameters<T>(
IQueryable<T> iQueryableOfAnonymous, DataTables.AspNet.Core.IDataTablesRequest request)
{
/*
* So, in "IQueryable<T> iQueryableOfAnonymous" I have the source data that I need to
* filter. In "DataTables.AspNet.Core.IDataTablesRequest request" I have full specification
* of request, including the search value "request.Search.Value" and specification of columns
* that need to be searched for marked by "IsSearchable".
* I use Reflection to check if names of entity T properties match column names in
* DataTables.AspNet.Core.IDataTablesRequest request and then create filter Linq query using
* System.Linq.Dynamic.Core library, and return Linq query as a result.
* It might look complicated, but advantage is that this method is generic and can
* be applied many times on different entities T.
*/

//this will work if type T contains properties that have names column.Name
if (request != null && request.Search != null && !System.String.IsNullOrEmpty(request.Search.Value))
{
string pattern = request.Search.Value?.Trim() ?? System.String.Empty;

var searchingColumns = request.Columns.Where(p => p.IsSearchable).ToList();
var config = new ParsingConfig { ResolveTypesBySimpleName = true };

Type objType = typeof(T);
var ListOfAllPropertiesInT = objType.GetProperties().Select(p => p.Name).ToList();

if (searchingColumns.Count > 0)
{
//we plan to build dynamic Linq expression in this string
string dynamicLinqSearch = string.Empty;
bool isFirstString = true;

for (int i = 0; i < searchingColumns.Count; i++)
{
var column = searchingColumns[i];

//check if that property exists in T,
//otherwise we will create syntax error in dynamic linq
if (ListOfAllPropertiesInT.Contains(column.Name))
{
if (isFirstString)
{
isFirstString = false;
}
else
{
dynamicLinqSearch += " or ";
}

dynamicLinqSearch += $"""{column.Name}.Contains("{pattern}")""";
}
}

if (dynamicLinqSearch.Length > 0)
{
//using System.Linq.Dynamic.Core
iQueryableOfAnonymous = iQueryableOfAnonymous.Where(config, dynamicLinqSearch);
}
}
}

return iQueryableOfAnonymous;
}










11 Conclusion



DataTables.net component looks nice and worked reasonably well in my prototype. Learning effort is not small, but if the component is used frequently in many projects, it pays off. It is good to have such a component in your toolset if you are an ASP.NET developer.



The problem with Open Source code is that you depend on the community to keep up-to-date components/libraries that you integrate into your code. Bugs happen, and that can be a problem. In this particular case, library DataTables.AspNet.Core is no longer maintained, so if interfaces of DataTables.net or ASP.NET change, you are on your own to fix the issue.



The full example code project can be downloaded at GitHub [99].






12 References



[1]


DataTables.AspNet.Core



[3]


Using DataTables Grid With ASP.NET MVC (MVC5)



[5]


Create a datatable in JQuery (pure jQuery)



[7]


Effortless Pagination with jQuery DataTables and Bootstrap (very basic)



[9]


Pagination In MVC With Jquery DataTable



[11]


System.Linq.Dynamic.Core



[13]


A FREE & Open Source LINQ Dynamic Query Library



[99] https://github.com/MarkPelf/ASPNET8UsingDataTablesNet

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Sam Altman calls GPT-6 Astra rollout ‘messy’ as enterprise users wait for access
1 Quelle
Swiss government explores replacing Microsoft 365 with open-source software
1 Quelle
What continuous operational resilience looks like under DORA
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten ASP.NET8 using DataTables.net – Part1 – Foundation

Thematisch verwandte Begriffe: ASPNET8, using, DataTablesnet, Part1 · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...