我想創建一個表單,如果他們希望用戶將編輯有個人檔案並上傳圖片, 這裏是我查看文件上傳在MVC 3總是空
//格式字符串@using(Html.BeginForm("EditProfile","Employee",FormMethod.Post, new { enctype = "multipart/form-data " }))
//輸入HTML <input type="file" name="file" id="file"/>
//提交<input type="submit" name="SubmitBtn" value="SaveProfile" /> <input type="submit" name="SubmitBtn" value="Cancel" />
現在我的控制器
//Profile Modification
[Authorize]
[HttpPost]
public ActionResult EditProfile(employer model, string SubmitBtn,HttpFileCollection file)
{
switch (SubmitBtn)
{
case "SaveProfile":
try
{
if (ModelState.IsValid)
{
//the file is always null
if (file != null)
{
//Function I want to Apply on file
model.logoname = logouploded(file);
return RedirectToAction("Profile", "Employer");
}
return RedirectToAction("EditProfile");
}
//ChangeEmployeeProfile(model);
}
catch (Exception ex)
{
ViewBag.warn = ex.Message;
return View(model);
}
break;
case "Cancel":
return RedirectToAction("index");
}
return View(model);
}
現在不管我上載的文件的文件總是來空 我也曾嘗試HttpFileCollectionBase在操作功能參數還是文件是空
僅舉員工的模型只包含圖片的文件名 因爲我只想要將圖像名稱保存在數據庫中。
嗨,你有沒有在回發後檢查'Request.Files'集合? –
刪除「multipart/form-data」中的最後一個空格。正確:「multipart/form-data」 –