3

I fail to upload pictures using formdata. This is my previous code which was working fine(This is just part of a form):

<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>

And this is my Ajax call:

$(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();

        }
    });
});

But my requirement has changed, I need to use Krajee plugin to create an input type: Here my new code:

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

</div>

what problem am I facing. I think the reason is I might need to do configuration for Krajee plugin but I'm not sure. Any suggestions?

1 Answer 1

3

I just found the answer. I lacked the name of the file input. Just do like this and the file will be regconized:

<input id="[email protected][i]" name= "fileInput" type="file" class="file" data-show-upload="false" data-show-caption="true" data-input-id="@Model.PictureIdList[i]">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.