Tôi có tải lên biểu mẫu hoạt động nhưng tôi muốn chuyển thông tin mô hình cho cơ sở dữ liệu của mình để lưu tệp có tên khác của khóa học.MVC 3 tải lên tệp và mô hình ràng buộc
Đây là quan điểm của tôi Razor:
@model CertispecWeb.Models.Container
@{
ViewBag.Title = "AddDocuments";
}
<h2>AddDocuments</h2>
@Model.ContainerNo
@using (Html.BeginForm("Uploadfile", "Containers", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<input type='file' name='file' id='file' />
<input type="submit" value="submit" />
}
Đây là điều khiển của tôi:
[HttpPost]
public ActionResult Uploadfile(Container containers, HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/Uploads"),
containers.ContainerNo);
file.SaveAs(path);
}
return RedirectToAction("Index");
}
Các thông tin mô hình không được truyền thông qua bộ điều khiển. Tôi đã đọc rằng tôi có thể cần phải cập nhật mô hình, làm thế nào tôi sẽ làm điều này?
Tham khảo http://stackoverflow.com/questions/9411563/asp-net-mvc3-razor-file-upload-gives-zero -as-file-count cho một vấn đề liên quan – Lijo