none
IformFile in the action controller takes the value as null, value is pass to the action controller using ajax request RRS feed

  • Question

  • I am trying to get the value passed from the ajax request into one of the method in the controller. If in the controller I pass (List<IFormFile> FormFile) then it is taking some value but if I only pass IFormFile files than the value of files is null every time. Here is my ajax request :

    uploadFile: function (field, value) { var me = this; var view = me.getView(); var fileuploadControl = me.lookupReference('ImportFile'); var file = fileuploadControl.fileInputEl.el.dom.files[0]; var param = new FormData(); param.append('files', file); var ajax = Ext.Ajax.request( { url: './../XYController/ImportCSVFile', data: param, method: 'POST', contentType: "application/json; charset=utf-8", dataType: "json", headers: { 'accept': '*/*' }, processData: true, success: function (response, options) { var result = JSON.parse(response.responseText); if (mask) { mask.destroy(); } Ext.Msg.alert("File Upload Successful"); } });

    },


    And this is my Action Controller :

    [HttpPost]
    [Route("XYController/ImportCSVFile")]
    public IActionResult ImportCSVFile(IFormFile files)
    {
      if(files!=null)
       {
        //do something
       }
    }
    • Moved by CoolDadTx Friday, January 10, 2020 3:02 PM ASP.NET related
    Tuesday, January 7, 2020 4:40 PM

All replies

  • Hi,
    I viewed your description, it is mainly related to ASP.NET Core. So it is recommended to go to this forum and you can get more professional answer.
    Besides, I find a similar issue you can refer to.
    [How to fix a null IFormFile being accepted by an ASP.NET Web Api from a Post]
    Hope it is useful for you.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 10, 2020 5:36 AM
  • This forum is for C#-specific questions only. Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, January 10, 2020 3:01 PM