Upload image with ajax, HttpPostedFileBase is null Mvc Asp

This question already has an answer here:

  • How can I upload files asynchronously? 27 answers

  • View

    Instead of Jquery Ajax you could use

    <script>
                function SubmitButtonOnclick()
                { 
                    var formData= new FormData();
                    var imagefile=document.getElementById("imageFile").files[0];
                    formData.append("imageFile",imageFile);
                    var xhr = new XMLHttpRequest();
                    xhr.open("POST", "/Help/AcceptUpload", true);
                    xhr.addEventListener("load", function (evt) { UploadComplete(evt); }, false);
                    xhr.addEventListener("error", function (evt) { UploadFailed(evt); }, false);
                    xhr.send(formData);
    
                }
    
          function UploadComplete(evt) {
            if (evt.target.status == 200) 
                    alert("Logo uploaded successfully.");
    
            else 
                     alert("Error Uploading File");
            }
    
        function UploadFailed(evt) {
            alert("There was an error attempting to upload the file.");
    
        }
     </script>
    
    链接地址: http://www.djcxy.com/p/19610.html

    上一篇: 用ajax发送输入类型文件值

    下一篇: 用ajax上传图片,HttpPostedFileBase为空Mvc Asp