2012-12-04 41 views
1

我试图用cshtml上传一个在MVC 3.0中的excel工作表。在我看来,我的页面中有两个按钮,每个按钮都有不同的操作结果。我已经实现了处理我的页面中的两个按钮。但是,当我点击上传按钮时,没有文件在Request.Files给出时。我应该在上传按钮点击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); 
} 

回答