jquery - How to import an Excel file into a Web Core API? -
i use file picker in web project select excel file. want send web core api method save save contained in file. jquery/ajax follows;
var uploadexcel = function () { var uploadurl = gethiddenfield("sir-excel-import-url"); var selectedfile = $("#selectedexcelfile"); var formdata = new formdata(); formdata.append("file", selectedfile[0].files[0]); $.ajax({ url: uploadurl, type: 'post', data: formdata, contenttype: false, processdata: false, async: true, success: function (data) { alert(data.success); }, error: function (error) { alert('error'); } }); }; the uploadurl = http://localhost:11111/api/importproperty/589/import file in view
<input type="file" name="file" id="selectedexcelfile" accept=".xls,.xlsx"> the web core api method starts as
[authorize] [route("api/importproperty")] public class propertyimportcontroller : controller { [httppost("{contractid}/import")] public async task<iactionresult> import(int contractid, [frombody] iformfile file) { if (contractid == 0) { return badrequest("contract not selected"); } yet method signature not being recognised. doing wrong?
Comments
Post a Comment