【问题标题】:jquery file upload in mvc while clicking on button单击按钮时在mvc中上传jquery文件
【发布时间】:2014-06-06 12:26:20
【问题描述】:

这里我使用 jQuery-File-Upload 来上传文件。它工作正常。但是当我们选择文件时这里文件正在上传,我需要在点击提交按钮后上传文件。 请帮助我如何解决这个问题。 我正在使用以下代码。

   $('#fileupload').fileupload({


        dataType: 'json',
        url: '/VendorReport/UploadFiles',
        autoUpload: true,
        type: boolen,
        Default:true,
        success: function (msg) {

            alert(msg);

        }
    });


<input id="fileupload" type="file" name="files[]">
<input type="submit" id="btnup" value="Upload" />

【问题讨论】:

  • 设置autoUpload: false,
  • 如果我保持 autoUpload:false 它不允许文件。我需要允许文件上传,点击提交按钮后需要工作。

标签: jquery asp.net-mvc-4 jquery-file-upload jquery-fileupload-rails


【解决方案1】:

您可以通过设置autoUpload: false来停止自动上传行为

$('#fileupload').fileupload({
    dataType: 'json',
    url: '/VendorReport/UploadFiles',
    autoUpload: false,
    type: boolen,
    Default:true,
    success: function (msg) {
        alert(msg);

    }
});

编辑

点击按钮上传文件:

HTML

<input id="fileupload" type="file" name="files[]">
<input type="submit" id="btnup" value="Upload" />

jQuery

$(document).ready(function(){
    $("#btnup").click(function(){
         $('#fileupload').fileupload({
            dataType: 'json',
            url: '/VendorReport/UploadFiles',
            autoUpload: false,
            type: boolen,
            Default:true,
            success: function (msg) {
                alert(msg);
            }
        });
    });
});

编辑

或者参考它的文档按照官方的方式--> How to start uploads with a button click

$('#fileupload').fileupload({
    dataType: 'json',
    url: '/VendorReport/UploadFiles',
    autoUpload: false,
    type: boolen,
    Default:true,
    success: function (msg) {
        alert(msg);
    }
    add: function (e, data) {
        data.context = $('<button/>').text('Click to Upload')
            .appendTo(document.body)
            .click(function () {
                data.context = $('<p/>').text('Uploading...').replaceAll($(this));
                data.submit();
        });
    }
});

【讨论】:

  • 点击提交按钮时如何上传文件..?
  • 是的,我得到了解决方案...谢谢@Log1c
  • 对不起兄弟,我不知道这个控件在asp.net中是如何工作的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-09-17
  • 1970-01-01
  • 2014-06-30
  • 2013-09-16
  • 1970-01-01
  • 2014-09-26
  • 1970-01-01
相关资源
最近更新 更多