<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")
}
没有什么影响;html5只是说在前端ui的展示和效果方面多了很多方式,而asp.net的aspx页面其实是一个动态html页面,html再怎么升级,在aspx页面中的使用方法都是不会改变的欢迎分享,转载请注明来源:内存溢出
评论列表(0条)