How to fix 'requested unknown parameter '0' for row 0'

How to fix 'requested unknown parameter '0' for row 0'

abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0
edited August 2015 in Free community support

I'm returning a list of objects from my Controller as JsonResult.
Structure of my object-

public class NumModel
    {
        int Number { get; set; }
        string Status { get; set; }

        public NumModel(int number, string status)
        {
            this.Number = number;
            this.Status = status;
        }
    }

Getting 'requested unknown parameter '0' for row 0' when trying to populate DataTable.

function populatefizzbuzzlist(data) {
        $("#results tbody").html("");
        debugger;
        var otable = $("#results").dataTable({
            "aaData": data,
            "aaSorting" :  [[0, "asc" ]],
            "bJQueryUI": true,
            "bFilter":              true,
            "bStateSave":              true,
            "bDestroy":              true,
            "bDeferRender":              true,
            "bProcessing":              true,
            "bPaginate": true,
            "bLengthChange": false,
            "iDisplayLength": 20,
            "bAutoWidth": true,
            "sScrollY": "500px",
            "aoColumns": [
            {
                "bSortable": true,
                "sClass": "left",
                fnrender: function (obj) {
                    return obj.aData.Number;
                }
             },
             {
                   "bSortable": true, "sClass": "left", fnRender: function (obj) {

                       var cellValue = obj.aData.Status;
                       if (cellValue == "fizz") {
                           return "<span class=\"greenText\">" + cellValue + "</span>";
                       }
                       else if (cellValue == "buzz") {
                           return "<span class=\"blueText\">" + cellValue + "</span>";
                       }
                       else {
                           return cellValue;
                       }

                       return obj.aData.Status;
                   }
             }
            ]
        });
        $("#results").css('width', "100%");

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Pre the forum rules, please link to a test case or show a debugger trace.

    Allan

  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0

    HTML1300: Navigation occurred.
    File: localhost:50915
    SCRIPT5007: Unable to get property 'length' of undefined or null reference
    File: jquery.dataTables.min.js, Line: 21, Column: 52
    HTML1513: Extra "<html>" tag found. Only one "<html>" tag should exist per document.
    File: localhost:50915, Line: 5, Column: 1
    HTML1503: Unexpected start tag.
    File: localhost:50915, Line: 6, Column: 1
    HTML1512: Unmatched end tag.
    File: localhost:50915, Line: 10, Column: 1
    HTML1514: Extra "<body>" tag found. Only one "<body>" tag should exist per document.
    File: localhost:50915, Line: 11, Column: 1
    HTML1506: Unexpected token.
    File: localhost:50915, Line: 28, Column: 5

  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0

    Bookmarklet code - igotoc

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I would suggest correct the HTML validation errors first. DataTables assumes that valid HTML is being used.

    Allan

  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0

    Fixed HTML errors. new bookmarklet code -ohizuk

  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0

    Exception was thrown at line 5163, column 8 in http://localhost:50915/Scripts/jquery-1.7.2.js
    0x800a139e - JavaScript runtime error: SyntaxError
    Unhandled exception at line 21, column 52 in http://localhost:50915/Scripts/DataTables/jquery.dataTables.min.js
    0x800a138f - JavaScript runtime error: Unable to get property 'length' of undefined or null reference
    The program '[1080] iisexpress.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
    The program '[8852] iexplore.exe' has exited with code -1 (0xffffffff).

  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0

    One finding...its able to receive a simple integer list. Its only when an object list is returned from C# it fails to bind correctly.AM I missing any references to recieve JSON?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You need to use columns.data to tell DataTables what data property from each row object to use. Example.

    Allan

  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0
    edited August 2015

    No luck.
    I'm not getting any errors now. But nothing gets displayed on the UI.
    Posting my definitions again.

    <table id="results" style="white-space:normal;background-color:transparent;width:100%;">
            <thead>
                <tr>
                  <th>Number</th>
                    <th>Status</th>
                </tr>
            </thead>
           
        </table> 
    

    public class Output { public int Number { get; set; } public string Status { get; set; } public Output(int number, string status) { this.Number = number; this.Status = status; } }
     var otable = $("#results").dataTable({
                "aaData": data,
                "aaSorting" :  [[0, "asc" ]],
                "bJQueryUI": true,
                "bFilter":              true,
                "bStateSave":              true,
                "bDestroy":              true,
                "bDeferRender":              true,
                "bProcessing":              true,
                "bPaginate": true,
                "bLengthChange": false,
                "iDisplayLength": 20,
                "bAutoWidth": true,
                "sScrollY": "500px",
                "columns": [
               { "data": "Number" },
               { "data": "Status" }
                ]
     });
    
  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0

    Ok...By putting a debugger I can see that it loaded data, but as soon as the method completes, everything gets cleared off the UI.

  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0

    Please help this is urgent....

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Please link to a test case showing the issue, so we can help to resolve your urgent problem.

    Allan

  • abhilashamishra17abhilashamishra17 Posts: 13Questions: 3Answers: 0

    Not sure how to write test cases for datatable load

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Use JSFiddle or https://live.datatables.net if you can't give us a link to your page.

    Allan

This discussion has been closed.