[英]ASP.NET MVC Razor form to EF Create form with file upload
我發現了許多使用MVC Razor視圖和關聯的控制器方法上傳文件的簡單示例,但其中有9個示例,其中包括將EF模型以及文件返還給控制器。 任何人都可以幫助他們擁有或找到的資源嗎?
在視圖模型中包含一個屬性:
class MyViewModel {
public HttpPostedFileBase MyFile { get; set; }
//other properties
}
將輸入的文件添加到表單中:
<input type="file" name="myFile" />
然后文件將通過您的模型進入:
public ActionResult Create(MyViewModel model) {
//model.MyFile will be myFile
}
public ActionResult SomeControllerFunction(EFModel model, HttpPostedFileBase ImageFile)
您有表格的地方
@using (Html.BeginForm("SomeControllerFunction", "SomeController", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
//various fields for the EF model, plus
<input type="file" name="ImageFile" id="ImageFile" />
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.