Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Languages
    • Angular
    • Angular js
    • Asp.net Core
    • C
    • C#
    • DotNet
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • Security
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
    • SEO Analyzer
    • Background Remover
  1. Home
  2. Blog
  3. ASP.NET MVC
  4. How to use Jquery Datatables in asp.net

How to use Jquery Datatables in asp.net

Date- May 27,2024

Updated Feb 2026

3837

Free Download Pay & Download
Jquery datatables

Creating an ASP.NET MVC Application with jQuery DataTables

In this article, we'll walk through the process of creating an ASP.NET MVC application that displays a list of employees using jQuery DataTables. This powerful plugin provides advanced interaction controls to any HTML table, making it a great choice for displaying data in a user-friendly manner.So we will learn how to use jquery datatables in asp.net. You have to follow these steps

Step 1: Setting Up the Project

Create a New ASP.NET MVC Project

Open Visual Studio and create a new ASP.NET MVC project. Name your project Datatablejquery.

Add the Employee Model

In the Models folder, create a new class named Employee.cs and add the following code:

        
            using System;
            using System.Collections.Generic;
            using System.ComponentModel.DataAnnotations;
            using System.Linq;
            using System.Web;

            namespace Datatablejquery.Models
            {
                public class Employee
                {
                    public int Id { get; set; }

                    [Required]
                    public string Name { get; set; }

                    [Required]
                    public string Position { get; set; }

                    [Required]
                    public string Office { get; set; }

                    [Required]
                    public int Age { get; set; }

                    [Required]
                    public decimal Salary { get; set; }
                }
            }
        
    

Step 2: Creating the Controller

Add HomeController

In the Controllers folder, create a new controller named HomeController.cs and add the following code:

        
            using Datatablejquery.Models;
            using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Web;
            using System.Web.Mvc;

            namespace Datatablejquery.Controllers
            {
                public class HomeController : Controller
                {
                    private static List<Employee> employees = new List<Employee>
                    {
                        new Employee { Id = 1, Name = "John Doe", Position = "Manager", Office = "New York", Age = 45, Salary = 90000 },
                        new Employee { Id = 2, Name = "Jane Smith", Position = "Developer", Office = "London", Age = 30, Salary = 60000 },
                        new Employee { Id = 3, Name = "Samuel Jackson", Position = "Tester", Office = "Sydney", Age = 28, Salary = 50000 },
                        new Employee { Id = 4, Name = "Alice Johnson", Position = "HR", Office = "New York", Age = 29, Salary = 55000 },
                        new Employee { Id = 5, Name = "Robert Brown", Position = "Developer", Office = "San Francisco", Age = 34, Salary = 70000 },
                        new Employee { Id = 6, Name = "Emily Davis", Position = "Designer", Office = "Chicago", Age = 31, Salary = 60000 },
                        new Employee { Id = 7, Name = "Michael Wilson", Position = "Developer", Office = "London", Age = 40, Salary = 80000 },
                        new Employee { Id = 8, Name = "Linda Thompson", Position = "Manager", Office = "Sydney", Age = 50, Salary = 95000 },
                        new Employee { Id = 9, Name = "William Harris", Position = "Developer", Office = "New York", Age = 35, Salary = 75000 },
                        new Employee { Id = 10, Name = "Barbara Clark", Position = "Designer", Office = "London", Age = 27, Salary = 58000 },
                        new Employee { Id = 11, Name = "James Lewis", Position = "Tester", Office = "San Francisco", Age = 32, Salary = 52000 },
                        new Employee { Id = 12, Name = "Patricia Walker", Position = "HR", Office = "Chicago", Age = 37, Salary = 60000 },
                        new Employee { Id = 13, Name = "Christopher Hall", Position = "Manager", Office = "Sydney", Age = 48, Salary = 92000 },
                        new Employee { Id = 14, Name = "Susan Allen", Position = "Developer", Office = "New York", Age = 29, Salary = 68000 },
                        new Employee { Id = 15, Name = "David King", Position = "Designer", Office = "San Francisco", Age = 33, Salary = 61000 },
                        new Employee { Id = 16, Name = "Sarah Scott", Position = "Tester", Office = "Chicago", Age = 30, Salary = 50000 },
                        new Employee { Id = 17, Name = "Richard Green", Position = "Developer", Office = "London", Age = 39, Salary = 77000 },
                        new Employee { Id = 18, Name = "Karen Baker", Position = "Manager", Office = "Sydney", Age = 45, Salary = 93000 },
                        new Employee { Id = 19, Name = "Joseph Gonzalez", Position = "HR", Office = "New York", Age = 41, Salary = 62000 },
                        new Employee { Id = 20, Name = "Nancy Perez", Position = "Developer", Office = "San Francisco", Age = 28, Salary = 64000 },
                    };

                    public ActionResult Index()
                    {
                        return View(employees);
                    }

                    // Optionally, create a method to return JSON data
                    public JsonResult GetEmployees()
                    {
                        return Json(employees, JsonRequestBehavior.AllowGet);
                    }

                    public ActionResult About()
                    {
                        ViewBag.Message = "Your application description page.";
                        return View();
                    }

                    public ActionResult Contact()
                    {
                        ViewBag.Message = "Your contact page.";
                        return View();
                    }
                }
            }
        
    

Step 3: Creating the View

Update the Index View

In the Views/Home folder, open the Index.cshtml file and update it with the following code:

        
            @model IEnumerable<Datatablejquery.Models.Employee>

            @{
                ViewBag.Title = "Employee List";
                Layout = "~/Views/Shared/_Layout.cshtml";
            }

            <h2>Employee List</h2>

            <table id="employeeTable" class="display">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Salary</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var employee in Model)
                    {
                        <tr>
                            <td>@employee.Id</td>
                            <td>@employee.Name</td>
                            <td>@employee.Position</td>
                            <td>@employee.Office</td>
                            <td>@employee.Age</td>
                            <td>@employee.Salary</td>
                        </tr>
                    }
                </tbody>
            </table>

            @section Scripts {
                <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
                <script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
                <link rel="stylesheet" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css" />

                <script>
                    $(document).ready(function () {
                        $('#employeeTable').DataTable();
                    });
                </script>
            }
        
    

Step 4: Adding DataTables Scripts and Styles

Include DataTables CSS and JS files within the Scripts section of the Index.cshtml file to enable DataTables functionality.

Step 5: Running the Application

Run Your Application

Press F5 or click the run button in Visual Studio to start the application. Navigate to the Index page where you should see the employee list displayed in a DataTable.


Conclusion

In this tutorial, we covered how to:

  • Set up an ASP.NET MVC project.
  • Create a model for employees.
  • Set up a controller to handle requests.
  • Use jQuery DataTables to display data in a user-friendly table.

DataTables provide an excellent way to enhance the interactivity and usability of data tables in web applications. With features like pagination, sorting, and search, they are a powerful tool for any developer working with large datasets in ASP.NET MVC.

Feel free to expand this setup with additional features like server-side processing, custom styling, and advanced interactions to suit your application needs.So this is how you can use jquery datatable in asp.net.


S
Shubham Batra
Programming author at Code2Night โ€” sharing tutorials on ASP.NET, C#, and more.
View all posts โ†’

Related Articles

Implement Stripe Payment Gateway In ASP.NET
Sep 10, 2020
Jquery Full Calender Integrated With ASP.NET
Sep 30, 2020
Microsoft Outlook Add Appointment and Get Appointment using Asp.Net MVC
Oct 03, 2020
How to implement JWT Token Authentication and Validate JWT Token in ASP.NET MVC using JWT
Oct 12, 2022
Previous in ASP.NET MVC
Integrating Google reCAPTCHA Validation in ASP.NET MVC
Next in ASP.NET MVC
Integrating ChatGPT API in ASP.NET

Comments

Contents

๐ŸŽฏ

Interview Prep

Ace your ASP.NET MVC interview with curated Q&As for all levels.

View ASP.NET MVC Interview Q&As

More in ASP.NET MVC

  • Payumoney Integration With Asp.Net MVC 23130 views
  • MVC Crud Operation with Interfaces and Repository Pattern wi… 21810 views
  • Using Ajax in Asp.Net MVC 21167 views
  • Stopping Browser Reload On saving file in Visual Studio Asp.… 20592 views
  • Exception Handling and Creating Exception Logs in Asp.net MV… 20428 views
View all ASP.NET MVC posts โ†’

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • Asp.net Core
  • C
  • C#
  • DotNet
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ยท  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor