我无法将参数传递给后端(从 Ajax 到 IActionResult 或 JsonResult).net core 5

i can not pass parameters to backend ( from Ajax to IActionResult or JsonResult) .net core 5

我有问题,我无法使用 fech 或 ajax 调用将参数传递给后端,但我可以从另一台 PC 传递参数,这是来自代码的示例

后端:

    [HttpPost]
    public IActionResult SubProducat(int Pid)
    {
        List<Lookup> SubProducat = new BAL.Lookups.LookupBL().SubProducatByProduct(Pid);
        return Json(SubProducat);
    }

** 这里 Pid 始终为零 **

JavaScript代码:

   $.ajax({
                async: false,
                type: "POST",
                url: '@Url.Action("GetSubProducat", "Notification")',
                data: JSON.stringify({ Pid: $("#ProducatId").val() }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var returnedData = $.parseJSON(data);
                    $('#SubProducatId').empty();
                    $('#SubProducatId').append("<option value='' selected>---Select---</option>");
                    $.each(returnedData, function (key, value) {
                        $('#SubProducatId').append(
                            '<option value="' + value.ID + '">'
                            + value.NameEN +
                            '</option>');
                    });
                },
                error: function (Edata) { alert(Edata); }
            }); 

试试下面的代码

$.ajax({
   type: "POST",
   url: '@Url.Action("SubProducat", "ControllerName")',
   data: $("#ProducatId").val() ,
   contentType: "application/x-www-form-urlencoded",
   dataType: "json",
   success: function (data) {
        ...
   },
   error: function (Edata) { alert(Edata); }
});