2012-12-04 39 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); 
} 

回答