0

I am trying to upload an image using jQuery AJAX and not sure how to go around doing it...

I am trying to send the data to controller just to see it working...

Here is my code

<form enctype="multipart/form-data">
    <div class="form-group">
        <input type="file" id="myFile">
    </div>
    <button type="button" id="uploadHero" class="btn btn-primary">Upload</button>
</form>


$("#uploadHero").click(function () {
    var data = new FormData();
    var files = $("#myFile").get(0).files;

    $.ajax({
        type: "POST",
        url: "Home/FileUpload",
        data: data
    });
});

    [HttpPost]
    public void FileUpload(HttpPostedFileBase heroFile)
    {


    }
2
  • did you tried putting the name attribute on input file 'heroFile' ? Commented Mar 10, 2020 at 12:19
  • Have tried that and still doesn't work Commented Mar 10, 2020 at 12:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.