我正在使用ASP.NET MVC-5,我有一个按钮,允许我选择多个文件进行输入,所以它适用于以下代码
<input type="file" name="file" multiple>如何从控制器获取文件,以便在HttpPost操作中的程序逻辑中使用它们?
发布于 2015-06-06 06:25:07
在本例中,您可以从HttpPostedFileBase数组获得控制器操作中的上载文件。
[HttpPost]
public ActionResult Index(HttpPostedFileBase[] uploadedfiles)
{
try
{
// Loop through array fro getting files
foreach (HttpPostedFileBase file in files)
{
// get current file name
string filename = System.IO.Path.GetFileName(file.FileName);
//Saving the file in relative path (server folder)
file.SaveAs(Server.MapPath("~/Images/" + filename));
string filepathtosave = "Images/" + filename;
/* code for saving the image into database */
}
ViewBag.Message = "File Uploaded successfully.";
}
catch
{
ViewBag.Message = "Error while uploading the files.";
}
return View();
}https://stackoverflow.com/questions/30678762
复制相似问题