0
我試圖上傳一個XML文件到我的網站。但是,無論我嘗試上傳哪個文件,我的代碼中的HttpPostedFileBase元素都是null。我不明白這是爲什麼。我已經遵循了我在上傳文件時可以找到的所有示例,但似乎沒有任何意義。這是控制器方法無法上傳文件ASP.NET MVC3。 XML文件到模型
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase xmlFile)
{
if (xmlFile != null && xmlFile.ContentLength > 0)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFile.InputStream);
// other logic later
return RedirectToAction("Index");
}
return RedirectToAction("UploadFailed");
}
和CSHTML:
@{
ViewBag.Title = "Upload";
}
@using (Html.BeginForm("UploadFile", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}
太好了。謝謝。真是愚蠢的錯誤。 – Bonnotbh 2012-03-01 22:49:44