【解決方法】ASP.NET コア カミソリ ページを使用して複数の ajax データをフォームに渡す方法

プログラミングQA


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.

私が試したこと:

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 = "https://www.codeproject.com/Trainees/Index?=${data}" class="btn btn-primary text-white">
                                </a>
                            </div>`
                },
                "width": "5%"
            }
        ],
        "width": "100%"
    });
});

解決策 1

あなたのコードは、データを /api/Employees 終点。

マニュアルには、それを行う方法の例があります。
ajax.data[^]

例えば:

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

あなたが作っているので、 GET 要求すると、データはクエリ文字列で渡されます。 代わりに本文でデータを渡したい場合は、エンドポイントとデータテーブル構成を変更して、 POST 代わりにリクエストしてください。

コメント

タイトルとURLをコピーしました