【问题标题】:Cannot upload picture using formdata Asp.net-mvc无法使用formdata Asp.net-mvc上传图片
【发布时间】:2015-06-19 09:37:15
【问题描述】:

我无法使用 formdata 上传图片。这是我之前运行良好的代码(这只是表单的一部分):

<div class="fileinput fileinput-new" data-provides="fileinput" style="width: 100%;">
                                                            <div class="fileinput-preview" data-trigger="fileinput" style="margin: 10px 0px;"></div>
                                                            <div>
                                                                <span class="btn btn-default btn-file">              
                                                                    <input type="file" id="filePicture" name="filePicture">
                                                                </span>

                                                            </div>
                                                        </div>

这是我的 Ajax 调用:

$(document).on("click", "#sledBuckSaveBtn", function() {
    event.preventDefault();
    event.stopPropagation();

    var fd = new FormData(document.getElementById("saveSledBuckForm1"));

    $.ajax({
        type: "POST",
        url: "/SledBuck/EditFromSledTestDetails", //url,
        data: fd,

        processData: false, // tell jQuery not to process the data
        contentType: false,
        success: function (result) {

            var title = "Error", msgtype = "error";
            if (result) {
                title = "Success";
                msgtype = "success";

            }

            document.location.reload();

        }
    });
});

但是我的要求变了,我需要使用 Krajee 插件来创建输入类型: 这是我的新代码:

  <div class="col-md-9">                                                                                                            
<input id="input-@Model.PictureIdList[i]" type="file" class="file" data-show-upload="false" data-show-caption="true" data-input-id="@Model.PictureIdList[i]">

</div>

我面临什么问题。我认为原因是我可能需要为 Krajee 插件进行配置,但我不确定。有什么建议吗?

【问题讨论】:

    标签: asp.net-mvc file input image-uploading form-data


    【解决方案1】:

    我刚刚找到了答案。我缺少文件输入的名称。只需这样做,文件就会被重新调整:

    <input id="input-@Model.PictureIdList[i]" name= "fileInput" type="file" class="file" data-show-upload="false" data-show-caption="true" data-input-id="@Model.PictureIdList[i]">
    

    【讨论】:

      猜你喜欢
      • 2018-05-02
      • 2016-06-24
      • 2010-10-05
      • 2021-08-27
      • 2022-12-17
      • 2017-04-07
      • 1970-01-01
      • 1970-01-01
      • 2015-11-16
      相关资源
      最近更新 更多