Click here to Skip to main content
15,884,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to pass jquery data values to another page's form. I've tried the suggested solutions I found in the net but still no luck.

The solution I am thinking is to add the data to my href and from there extract the values and add to my fields.


What I have tried:

Here is the code I tried but failed:

JavaScript
<pre>$(document).ready(function () {
    dataTable = $('#DT_employees').DataTable({
        "pageLength": 50,
        "ajax": {
            "url": "/api/Employees",
            "type": "GET",
            "datatype": "json"
        },
        "columns": [
            { "data": "employeeId", "width": "10%" },
            { "data": "userName", "width": "10%" },
            { "data": "firstName", "width": "10%" },
            { "data": "lastName", "width": "10%" },
            {
                "data": "{employeeId, firstName, lastName}",
                "render": function (data) {
                    return `<div class="w-75 btn-group">
                                <a href = "/Trainees/Index?=${data}" class="btn btn-primary text-white">
                                </a>
                            </div>`
                },
                "width": "5%"
            }
        ],
        "width": "100%"
    });
});
Posted
Updated 17-Apr-23 0:34am

1 solution

Your code doesn't attempt to pass any data to the /api/Employees endpoint.

The manual has an example of how you would do that:
ajax.data[^]

Eg:
JavaScript
"ajax": {
    "url": "/api/Employees",
    "type": "GET",
    "data": function ( d ) {
        d.extra_search = $('#extra').val();
    }
}

Since you're making a GET request, the data will be passed in the querystring. If you want to pass the data in the body instead, then change your endpoint and your datatable configuration to use a POST request instead.
 
Share this answer
 
Comments
Markeeh 18-Apr-23 0:06am    
Thanks @Richard Deeming!
This was also answered in https://stackoverflow.com/questions/76033529/pass-multiple-ajax-data-to-form-using-asp-net-core-razor-pages/76040808#76040808

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900