reading Mvc razor model cell data

reading Mvc razor model cell data

rangaranga Posts: 31Questions: 12Answers: 2
edited October 2018 in General

I just came to know that when we use razor model data in mvc with datatables like

  <td>
                    @Html.TextBoxFor(modelItem => item.JobID)
                </td>

cells(). data will not return any data . like

 var table = $('#example').DataTable()
 table.on('click', function () {
             
                alert($('td', this).eq(0).text());
               var  data = table.cells(this,0).data();
                alert(data);
})

Any one else experienced the same is there something i got wrong. i saw some article said only displayfor and editorfor is not supporting to extract data but textboxfor is not helping either.

Please help if someone could . thank you.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,296Questions: 26Answers: 4,768
    Answer ✓

    Changing the click event selector seems to help:
    http://live.datatables.net/begavape/1/edit

      
      table.on('click', 'td', function () {
        console.log($(this).eq(0).text());
        var  data = table.cells($(this),0).data().toArray();
        console.log(data);
      
      })
    

    Kevin

  • rangaranga Posts: 31Questions: 12Answers: 2

    @Kevin Thanks a lot bro 'td was the missing piece.
    Thanks mate

This discussion has been closed.