Search code examples
c#file-uploadasp.net-coreasp.net-core-2.0bootstrap-file-upload

Not receiving any data from file upload


I am trying to use the Krajee Bootstrap File Input to upload a file. I am using ASP.NET Core 2. Here is my HTML:

<input id="fileFileUpload" type="file" />

Here is my javascript code:

    $("#fileFileUpload").fileinput({
        showPreview: true,
        uploadAsync: false,
        uploadUrl: '/fileupload'
    });

Here is my controller code:

[HttpPost]
public JsonResult Index(List<IFormFile> files)
{
    // Do stuff
}

I am putting a breakpoint on my controller method and the breakpoint is being hit. However files is empty. How can I retrieve the file that was uploaded?


Solution

  • The number one reason I can see for that code not work is that your input in not assigned a name.

    <input id="fileFileUpload" name="files" type="file" />
    

    Other then that you can follow this MSDN article.