How to send multipart/form-data to ASP.NET Core Web API? How to send multipart/form-data to ASP.NET Core Web API? asp.net asp.net

How to send multipart/form-data to ASP.NET Core Web API?


Maybe you should try decorate controller input and model with [FromForm] attribute?See more info here: web api parameters binding.

In given example your controller action should look like this:

[HttpPost("/api/account"), Authorize]public void SaveUser([FromForm]UserModel info)

In model:

[FromForm(Name="avatar")]public IFormFile Avatar { get; set; }[FromForm(Name="name")]public string Name { get; set; }


Here is a working example for what you are looking for

Controller:

[HttpPost]public async Task<IActionResult> SaveFile([FromForm] IFormFile file) {  // Your code here}

And inside your model:

public IFormFile File { get; set; }

Change async Task<IActionResult> if you don't need it...