<httpRuntime targetFramework="4.5" requestValidationMode="2.0" />
<pages validateRequest="false" clientIDMode="AutoID"></pages>
</system.web>
加上这个就行了,不要问我为什么,可以自己百度一下
Html 5 的有一些File API,对Form表单增强的特性,让我们轻松支持多文件上传,看下面的Html片断代码:<form action="/Home/Upload" enctype="multipart/form-data" id="form2" method="post">
<input type="file" name="fileToUpload" id="fileToUpload2" multiple="multiple" />
<input type="submit" value="submit" />
</form>
那在Asp.net MVC web application中,我们可以这么实现:
@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data", id = "form2" }))
{
<label for="file">Upload Image:</label>
<input type="file" name="fileToUpload" id="fileToUpload2" multiple="multiple" />
<input type="submit" value="Upload Image by submit" />
}
假设这是一个HomeController下View, 即将提交到Upload的Action,看下面服务端的代码:
[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")
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)