文件上传无论在软件还是在网站上都十分常见,我今天再把它拿出来,讲一下,主要讲一下它的设计思想和实现技术,为了它的通用性,我把它做在了WEB.Service项目里,即它是针对服务器的,它的结构是关联UI(WEB)层与Service层(BLL)的桥梁.
结构
上传基类:
上传文件的接口规范:
接口的实现:
UI层调用WEB.Service层的上传功能:(附代码)
public class FileUploadController : Controller { WEB.Services.IFileUpload iFileUpload = null; public FileUploadController() { iFileUpload = new WEB.Services.FileUpload(); } #region 文件上传 public ActionResult uploadheadpic() { return View(); } [HttpPost] public ActionResult uploadheadpic(FormCollection formcollection) { if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; Entity.Commons.VMessage vm = iFileUpload.Image(WEB.Services.UpLoadType.DownloadUrl, file); if (vm.IsComplete) TempData["PicUrl"] = "{result:true,msg:\"" + vm[0].Replace("\"", "") + "\"}"; else TempData["PicUrl"] = "{result:false,msg:\"" + vm[0].Replace("\"", "") + "\"}"; } return View(); } #endregion }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)