Phần View
Mã:
@using (Html.BeginForm("UpdateImage","UploadFile",FormMethod.Post, new { enctype = "multipart/form-data"}))
{
<div>
<label for="fileUpload">File upload</label>
<input type="file" id="fileUpload" name="fileUpload" />
</div>
<div>
<input type="submit" value="Submit" />
</div>
}
Phần Controller
Mã:
public ActionResult UploadFile()
{
return View();
}
[HttpPost]
public ActionResult UploadFile()
{
foreach (string upload in Request.Files)
{
if (Request.Files[upload].ContentLength == 0) continue;
string pathToSave = Server.MapPath("~/Content/Images/");//Phần vị trí lưu File .
string filename = Path.GetFileName(Request.Files[upload].FileName);
Request.Files[upload].SaveAs(Path.Combine(pathToSave, filename));
ModelState.AddModelError("", "Update thanh cong");
}
return View();
}
View more random threads:
Pallet nhựa Long An đã trở thành một trong những lựa chọn phổ biến cho nhu cầu vận chuyển và lưu trữ hàng hóa trong nhiều ngành công nghiệp. Với đặc tính nhẹ nhàng, chắc chắn và dễ vận chuyển, các...
Thanh lý pallet nhựa Long An giá rẻ