Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

333
Vistas
Using DataTables Plugin in Razor View - Cannot set properties of undefined (setting '_DT_CellIndex') Error

I am using a asp.net mvc web app. I have created a table and now I am wanting to use the plugin in datatables. I saw you only needed 3 lines of code to make this work. I attempted to do exactly what it required in order for it to work and give me the desired datatable, but it does not give me the table I am expecting. I even went to examples -> HTML (DOM) source data -> and under Javascript tab I entered the lines required.

Is there something I am doing incorrect here with the script tags or is the plug in just not working? I do not have the files downloaded and imported to my project.

Expecting a standard look like this enter image description here

But am getting this... so I am missing the look of the datatable plugin and the following Error.

Cannot set properties of undefined (setting '_DT_CellIndex')

my view:

@model List<Fright>


@{
    ViewData["Title"] = "Home Page";
     var result = Model.GroupBy(gb => gb.Value);
}

<!DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <link href="//cdn.datatables.net/1.11.2/css/jquery.dataTables.min.css" rel="stylesheet"/>
    <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.11.2/js/jquery.dataTables.min.js" defer></script>
    <script>
        $(document).ready(function () {
            $('#homeTable').DataTable();
        });
    </script>
</head>
<body>
    <div>
        <table id="homeTable" class="display" style="width:100%">
            <thead>
                <tr>
                    <th>Value</th>
                    <th>Option</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in result)
                {
                    var url = "/frightSummary/SummaryIndex?id=" + item.Key;
                    <tr>
                        <td>
                            <a href=@url>@item.Key</a>
                        </td>
                    </tr>

                }
            </tbody>
        </table>
    </div>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your problem is a mismatch in the number of <td> </td>. You are just rendering 1 <td> in foreach loop but you have two <th></th> in the table header

@model List<Fright>


@{
    ViewData["Title"] = "Home Page";
     var result = Model.GroupBy(gb => gb.Value);
}

<!DOCTYPE html>
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <link href="//cdn.datatables.net/1.11.2/css/jquery.dataTables.min.css" rel="stylesheet"/>
    <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.11.2/js/jquery.dataTables.min.js" defer></script>
    <script>
        $(document).ready(function () {
            $('#homeTable').DataTable();
        });
    </script>
</head>
<body>
    <div>
        <table id="homeTable" class="display" style="width:100%">
            <thead>
                <tr>
                    <th>Value</th>
                    <th>Option</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in result)
                {
                    var url = "/frightSummary/SummaryIndex?id=" + item.Key;
                    <tr>
                        <td>
                            <a href=@url>@item.Key</a>
                        </td>
                    <td>
                            <a href=@url>@item.Option</a> /* output you Option value*/
                        </td>
                    </tr>

                }
            </tbody>
        </table>
    </div>
</body>
</html> ```
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda