0

I'm trying to upload an image in my web application. But I get the error stated as the title. Please see my code below.

Index.cshtml

<form enctype="multipart/form-data">
    <div class="row">
        <div class="col-md-4">
            <input type="file" id="image" />
        </div>
        <button id="upload">Upload</button>
    </div>
</form>

Ajax

$('#upload').click(function () {

     var fileUpload = $("#image").get(0).files;
     $.ajax({
        type: 'POST',
        url: 'Insert',
        data: {
          Name: 'Test',
          floor: '6th',
          capacity: '3',
          file: fileUpload[0]
         },
        cache: false,
        success: function (data) {
             alert("SUCCESS!");
        }, error: function(){
             alert("ERROR");
        }
        });
    });

Thank you

jcubic
  • 61,973
  • 54
  • 229
  • 402

0 Answers0