public IActionResult Create(Computer computer, IFormFile file) { try { if (ModelState.IsValid) { if (file.Length > 0) { var path = Path.Combine("wwwroot/images", file.FileName); var stream = new FileStream(path, FileMode.Create); file.CopyToAsync(stream); computer.Photo = "images/" + file.FileName; _service.Create(computer); return(RedirectToAction("Index")); } else { ViewBag.Msg = "Fail..."; } } } catch (Exception ex) { ViewBag.Msg = ex.Message; } return(View()); }