I do not understand why in the controller productId comes 0. Here is the controller:

  [Route("Test/Post")] public async Task<ActionResult> PostTest(IFormFile files, int productId) { if (ModelState.IsValid) { string path = null; if (files != null) { path = "/ProductImages/" + files.FileName; using (var fileStream = new FileStream(_env.WebRootPath + path, FileMode.Create)) { await files.CopyToAsync(fileStream); } return Ok(productId); } else return BadRequest("Model is not valid"); } else return BadRequest("Model is not valid"); } 

I try:

enter image description here

  • I think checking files for null after accessing files.FileName is a bit late. - Igor
  • @Igor it means that the files come null, why? - Vitaly Shebanits

0