ajax other parameter is null?

问题描述 投票:0回答:1

为什么我的其他参数为null。当我的“ postedFile”和“ amount”具有数据时,“ date”和“ ids”为null。但是当我尝试删除“ postedFile”参数时。 id和日期具有值。而且效果很好。但我需要postedfile参数

我的脚本

  var ids = [];
function add(id, isChecked) {
    if (isChecked) {
        ids.push(id);
    }
    else {
        var i = ids.indexOf(id);
        ids.splice(i, 1);
    }
}

function saveSelected() {
    //var shipmentId = $('#c-shipment-id').val();
    var date = $('#Date').val();
    var amount = $('#Amount').val();
    //var ImageFile = $('#imageUploadForm').val();

    $('#imageUploadForm').on("change", function () {
        var formdata = new FormData($('form').get(0));
        CallService(formdata);
    });

    function CallService(postedFile) {
        $.ajax({
            url: '@Url.Action("index", "payment")',
            type: 'POST',
            data: { ids: ids, amount: amount, date: date, postedFile: postedFile },
            cache: false,
            processData: false,
            contentType: false,
            traditional: false,
            dataType:"json",
            success: function (data) {
                alert("Success");
            }
        });
    }
}

我的控制器

public ActionResult Index(int?[] ids, decimal? amount, DateTime? date, HttpPostedFileBase postedFile)
    {
        return View();
    }
asp.net-mvc asp.net-ajax
1个回答
0
投票

作为上述注释,我想您可以尝试传递所有带有参数的值,而不是像CallService(formdata, ids, amount, date)这样的变量。可能有效。

© www.soinside.com 2019 - 2024. All rights reserved.