我尝试使用cshtml在MVC 3.0中上传一个excel工作表。在我看来,我的页面中有两个按钮,每个按钮对应一个不同的操作结果。我在我的页面中实现了两个按钮的处理。但是,当我单击upload按钮时,当给出Request.Files时没有文件。我应该在Upload按钮点击的ActionResult中添加一个参数吗?下面是我的代码
[HttpPost]
[MultiButton(MatchFormKey = "Upload", MatchFormValue = "Upload")]
public ActionResult UploadFile()
{
TMReportViewModel UploadModel = new TMReportViewModel();
foreach (string file in Request.Files)
{
HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
if (hpf.ContentLength == 0)
continue;
string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(hpf.FileName));
hpf.SaveAs(savedFileName);
}
return View(UploadModel);
}发布于 2014-02-11 01:11:07
我目前正在使用ASP.NET MVC4.0来解决这个问题。
解决方案在HTML中,它就在那里:
你必须要写
@using (Html.BeginForm("UploadImage", "Image", FormMethod.Post,
new { enctype = "multipart/form-data" }))以便您的控制器知道您正在以Request.File格式传递图像。
有关更多信息,请查看。
而对于ASP.NET MVC3.0,可以看看。
https://stackoverflow.com/questions/13699850
复制相似问题