用ajax上传图片,HttpPostedFileBase为空Mvc Asp

这个问题在这里已经有了答案:

  • 我怎样才能异步上传文件? 27个答案

  • 视图

    你可以使用Jquery Ajax来代替

    <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/19609.html

    上一篇: Upload image with ajax, HttpPostedFileBase is null Mvc Asp

    下一篇: How to use JQuery post method