Upload file using Ajax call using ASP.NET MVC

前端 未结 2 1081
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 03:28

I would like to upload a file in my page using:


I have a button, clicking on which an ajax po

2条回答
  •  花落未央
    2021-01-06 04:02

    Code show here

            if (window.FormData !== undefined) {
    
                    var fileUpload = $("#FileUpload1").get(0);
                    var files = fileUpload.files;
    
    
                    var fileData = new FormData();
                    fileData.append('Type', Type );  //other requered pass data
                    fileData.append('name', dataRow.CustomerName);  //other requered pass data
                    fileData.append('Id', dataRow.InvoiceId);  //other requered pass data
                    fileData.append('subject', Sub);  //other requered pass data
                    fileData.append('message', Mess);  //other requered pass data
    
                    for (var i = 0; i < files.length; i++) {
                        fileData.append(files[i].name, files[i]);
                    }
    
                    $.ajax({
                        url: '/Email/SendEmail',
                        type: "POST",
                        contentType: false,
                        processData: false,
                        data: fileData,                     
                        success: function (data) {
    
                if (data == "No") {
                    alert("Email Not Exist in Customer Master." );
                }
                if (data == "Not") {
                    alert("Email Not Exist in System Setting.");
                }
                if (data == "NotExist") {
                    alert("File Not Exist or Some Other Error");
                }
                if (data == "PassNot") {
                    alert("Email Password Not Exist in System Setting.");
                } 
                if (data == "NotFile") {
                    $('btn-Print').trigger('click');
                }
                        },
                        error: function (err) {
                            alert(err.statusText);
                        }
                    });
                } else {
                    alert("FormData is not supported.");
                }
    

提交回复
热议问题