Requested unknown parameter for 'id' for row 0

Requested unknown parameter for 'id' for row 0

tnthieutnthieu Posts: 26Questions: 9Answers: 0
edited December 2019 in Free community support

Hi all,

Please hhhhhhhhhelp !!!!!!!!
I set up a datatable like this

var table = $('#jobs-table').dataTable({
        ajax: {
            type: "POST",
            url: "/JeopardyService.svc/GetJobsGrid",
            processData: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            dataSrc: function (json) {
                //debugger;
                return json.d;
            }
        },        
        columns: [
            {
                data: 'JobId'
            },
            {
                data: 'LastEditor'
            },
            {
                data: 'NumberOfEdits'
            }
        ]        
    });

The result of json is : d:"[{"JobId":"1","LastEditor":"LastEditor","NumberOfEdits":"1"}]"
so I set dataSrc return json.d

But I still get the error "Requested unknown parameter for 'JobId' for row 0"
Do you know why?

html
<table id="jobs-table" class="table table-hover table-condensed" style="width: 100%">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>LastEditor</th>
                        <th>NumberOfEdits</th>
                    </tr>
                </thead>
            </table>

On server:

[OperationContract]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.WrappedRequest,
            ResponseFormat = WebMessageFormat.Json
         )]
        public string GetJobsGrid()
        {
         
            List<Job> jobs = new List<Job>();

            Job job = new Job();
            job.JobId = "1";
            job.LastEditor = "LastEditor";
            job.NumberOfEdits = "1";
            jobs.Add(job);

            return JsonConvert.SerializeObject(jobs);
        }

[Serializable]
    public class Job
    {
        public string JobId { get; set; }
        public string LastEditor { get; set; }
        public string NumberOfEdits { get; set; }
    }

Thank you
Tang

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    It looks like the data is wrong:

    d:"[{"JobId":"1","LastEditor":"LastEditor","NumberOfEdits":"1"}]"
    

    d is a string in that data, and not an element. If you follow the tech note in that error, here for your reference, that should help. You probably want a JSON.parse() on the returned data,

    Colin

  • tnthieutnthieu Posts: 26Questions: 9Answers: 0

    thank you very much Colin

This discussion has been closed.