如何在控制器中传递上传Excel到操作方法时在ajax调用中添加更多参数

在我的代码中,Excel文件由用户在视图HTML中上传,并通过ajax获取该文件并传递给 ASP.NET MVC中的操作方法。我的代码工作正常,但我的问题是我想再添加两个参数传递给文件一起操作方法。如何实现此目的?


function uploadUserProfileDetails() {

    var excelUpload = $('#excelUpload').get(0);

    var excelfiles = excelUpload.files;

    var excelFileData = new FormData();


    for (var i = 0; i < excelfiles.length; i++) {

        excelFileData.append(excelfiles[i].name, excelfiles[i]);

    }


    $.ajax({

            type: "POST",

            enctype: "multipart/form-data",

            url: "/VCModule/UploadVCSchedule",

            data: excelFileData,

            dataType: "json",

            processData: false,

            contentType: false,

            async: false,

            success: function (data) {

            },

            error: function (response) {

            }

        });

    }

}


茅侃侃
浏览 102回答 2
2回答

米琪卡哇伊

试试这个,&nbsp; var abc = {&nbsp; &nbsp; 'modelfieldname':excelFileData,&nbsp; &nbsp; 'modelfieldname1':data1,&nbsp; &nbsp; 'modelfieldname2':data2,};&nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; type: "POST",&nbsp; &nbsp; &nbsp; &nbsp; enctype: "multipart/form-data",&nbsp; &nbsp; &nbsp; &nbsp; url: "/VCModule/UploadVCSchedule",&nbsp; &nbsp; &nbsp; &nbsp; data: abc,&nbsp; &nbsp; &nbsp; &nbsp; dataType: "json",&nbsp; &nbsp; &nbsp; &nbsp; processData: false,&nbsp; &nbsp; &nbsp; &nbsp; contentType: false,&nbsp; &nbsp; &nbsp; &nbsp; async: false,&nbsp; &nbsp; &nbsp; &nbsp; success: function (data) {&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; error: function (response) {&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });}

30秒到达战场

她的解决方案是有效的。var awardfamilyid = 105;//in Ajax method :-excelFileData.append(awardfamilyid, JSON.stringify(awardfamilyid));//In Action Method :-int AwardFamilyID = Convert.ToInt32(Request.Form.Keys[0]);
打开App,查看更多内容
随时随地看视频慕课网APP