在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
复制代码 代码如下: <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Files uploaded to server</h2> <div id="dialog" title="Upload files"> <% using (Html.BeginForm("Upload", "File", FormMethod.Post, new { enctype = "multipart/form-data" } )) <br /> 然后,我们需要根据BeginForm中FileController和action(Upload)在指定的Controller中处理请求,参考如下代码: 复制代码 代码如下: public void Upload( { foreach (string inputTagName in Request.Files) { HttpPostedFileBase file = Request.Files[inputTagName]; if (file.ContentLength > 0) { string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads") , Path.GetFileName(file.FileName)); file.SaveAs(filePath); } } RedirectToAction("Index", "File"); } |
请发表评论