Mam przesyłanie formularzy, które działa, ale chciałbym przekazać informacje o modelu dla mojej bazy danych, aby zapisać plik pod inną nazwą.Przesyłanie pliku MVC 3 i modelowanie
Oto mój widok 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" />
}
Oto moja Kontroler:
[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");
}
Informacje model nie przepuszcza do sterownika. Czytałem, że być może będę musiał zaktualizować model, jak to zrobić?
Patrz http://stackoverflow.com/questions/9411563/asp-net-mvc3-razor-file-upload-gives-zero -as-file-count dla powiązanego problemu – Lijo