复制代码 代码如下:
<form action="/Home/Upload" enctype="multipart/form-data" method="post">
<input type="file" multiple="multiple" />
<input type="submit" value="submit" />
</form>
复制代码 代码如下:
@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data", id = "form2" }))
{
<label for="file">Upload Image:</label>
<input type="file" multiple="multiple" />
<input type="submit" value="Upload Image by submit" />
}
复制代码 代码如下:
[HttpPost]
public ActionResult Upload(HttpPostedFileBase[] fileToUpload)
{
foreach (HttpPostedFileBase file in fileToUpload)
{
string path = System.IO.Path.Combine(Server.MapPath("~/App_Data"), System.IO.Path.GetFileName(file.FileName));
file.SaveAs(path);
}
ViewBag.Message = "File(s) uploaded successfully";
return RedirectToAction("Index");
}
希望对您Web开发有帮助。
新闻热点
疑难解答
图片精选