我正在尝试在ASP.NET MVC中上传单个.csv文件。在我的.ascx文件中,我有:
<div>
<input type="file" name="file" id="file" />
   
<input type="submit" name="btnSubmit" id="btnSubmit" value="Upload" />
</div>控制器操作为:
public ActionResult Upload(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
return View();
}问题是我总是在Upload Action中将file设为Null。关于如何让它工作有什么建议吗?
发布于 2012-04-06 00:18:35
你确定你有一个
<form enctype="multipart/form-data" method="post">
<div> bla bla
</div>
</form>编辑: method="post“
+
[HttpPost]在你的行动中
https://stackoverflow.com/questions/10032087
复制相似问题