Am trying to upload an excel sheet in MVC 3.0 using cshtml. In my view, I have two buttons in my page, for each button a different action result. I have implemented the handling of two buttons in my page. However, when i click on the upload button, no files are there when Request.Files is given. Should i add a parameter in the ActionResult of Upload button click? below is my code for
[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);
}