Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

334
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda