Asp.netMVC中Ajax.BeginForm上傳文件

 

作一個上傳並解壓的功能,解壓完了回調,解壓多少文件。搞了半天用Ajax.BeginForm。各類坑,後來直接放棄java

@using (Ajax.BeginForm("UploadFile", "ChaptersAndsections",

            new AjaxOptions()
            {
                HttpMethod = "post",
                OnSuccess = "onSuccess",
                OnFailure = "onFailure",
                OnComplete = "onComplete"
            },
           
            new { data_ajax = "false", enctype = "multipart/form-data"}))
        {

        <div>
            <input type="text" name="bid" value='@ViewData["id"]' id="id" hidden="hidden" />
            <label for="file1">文件名稱:</label>
            <input type="file" name="fileName" id="file1" required="required" multiple="multiple" />



            <input type="submit" id="ajaxBtn1" value="上傳解壓壓縮包" />
        </div>

        }

  

去掉這個吧,後臺獲取不到文件名,加上吧不執行回調,這個真。。。(真心想用,可是搞不定)哪一個園友能夠解決,請留言ajax

換種方法吧post

<div class="row">
            <div id="main">
                <h1>請選擇要解壓的文件</h1>
                <form id="uploadfrm" method="post" enctype="multipart/form-data" action="/ChaptersAndsections/UploadFile">
                    <input type="text" name="bid" value='@ViewData["id"]' id="id" hidden="hidden" />
                    <input type="file" name="fileName" id="images" />
                </form>
                <div id="response"></div>
                
                <button onclick="UploadUnZip();">上傳並解壓</button>
            </div>
            
        </div>

  

 function UploadUnZip() {
            var form = document.getElementById('uploadfrm');
            var formData = new FormData(form);
            $.ajax({
                url: "/ChaptersAndsections/UploadFile",
                type: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (data) {
                         //這個地方能夠填寫本身的方法
                 document.getElementById("response").innerHTML = data;
                }
            });
        }

  以下:ui

後臺url

相關文章
相關標籤/搜索