you can try below code
public class UploadImage
{
public string ImageFile { get; set; }
public string ImageName { get; set; }
public string ImageDescription { get; set; }
}
<form class="form-horizontal" asp-controller="Image" asp-action="UploadImage" method="POST" enctype="multipart/form-data">
<input type="file" asp-for="ImageFile">
<input type="text" asp-for="ImageName">
<input type="text" asp-for="ImageDescription">
</form>
public class Image
{
private IHostingEnvironment _hostingEnv;
public Image(IHostingEnvironment hostingEnv)
{
_hostingEnv = hostingEnv;
}
[HttpPost]
public async Task<IActionResult> UploadImage(UploadImage model, IFormFile ImageFile)
{
if (ModelState.IsValid)
{
var filename = ContentDispositionHeaderValue.Parse(ImageFile.ContentDisposition).FileName.Trim('"');
var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images", ImageFile.FileName);
using (System.IO.Stream stream = new FileStream(path, FileMode.Create))
{
await ImageFile.CopyToAsync(stream);
}
model.ImageFile = filename;
_context.Add(model);
_context.SaveChanges();
}
return RedirectToAction("Index","Home");
}