[Consumes("multipart/form-data")]//cho phep nhan kieu du lieu truyen len la form-data public async Task <IActionResult> Create(ProductCreateDto dto) { if (!ModelState.IsValid) { var suppliers = await _supplierService.GetAllSuppliers(); ViewBag.Suppliers = suppliers.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }); var manufactures = await _manufactureService.GetAll(); ViewBag.Manufactures = manufactures.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }); var categories = await _categoryService.GetAllCategories(); ViewBag.Categories = categories.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }); return(View(dto)); } var result = await _productSevice.Create(dto); if (result) { TempData["result"] = "Thêm sản phẩm thành công"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Thêm sản phẩm thất bại"); return(View(dto)); }