asp.net-mvc – 带有jquery-file-upload的asp.net mvc 4 Request
发布时间:2020-12-16 03:44:58 所属栏目:asp.Net 来源:网络整理
导读:我目前正在使用asp.net mvc 4,并使用 jquery-file-upload来上传图片,如果我这样初始化: $('#fileupload').fileupload(); $('#fileupload').fileupload('option',{ //url: '/Admin/News/Create',maxFileSize: 500000000,acceptFileTypes: /(.|/)(gif|jpe?g
我目前正在使用asp.net mvc 4,并使用
jquery-file-upload来上传图片,如果我这样初始化:
$('#fileupload').fileupload(); $('#fileupload').fileupload('option',{ //url: '/Admin/News/Create',maxFileSize: 500000000,acceptFileTypes: /(.|/)(gif|jpe?g|png)$/i,maxNumberOfFiles: 1,resizeMaxWidth: 1920,resizeMaxHeight: 1200,}); 当选择图像文件时,图像可以在borwser中预览,但在mvc Action Request.Files.Count为0时,表示没有上传文件. //$('#fileupload').fileupload(); $('#fileupload').fileupload('option',}); 我无法预览图像,但mvc Action获取文件,有谁知道为什么? [HttpPost] [ValidateInput(false)] public ActionResult Create(NewsViewModel model,FormCollection form) { if (ModelState.IsValid) { //.... // upload image foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue; string path = Path.Combine(Server.MapPath("~/Uploads/News/"),GUID.NewGuid()+ Path.GetExtension(hpf.FileName)); hpf.SaveAs(path); data.ImagePath = path; _iNewsService.UpdateNews(data); } } } 解决方法
我有同样的问题,解决了以下问题:
[HttpPost] [ValidateInput(false)] public ActionResult Create(NewsViewModel model,FormCollection form) { var length = Request.ContentLength; var bytes = new byte[length]; Request.InputStream.Read(bytes,length); //or for creating image from stream Bitmap bmp = new Bitmap(Bitmap.FromStream(InputStream)); bmp.Save("some path"); } 希望这可以帮助. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – Route属性上的RouteOrder属性在哪里?
- Asp.NET控制文件上传的大小方法(超简单)
- asp.net-mvc – 为什么Visual Studio 2010混合了System.Web
- asp-classic – 如何检查VBScript中是否存在POST提交字段?
- asp.net-mvc – 为什么ASP.NET MVC上的控制器基于名称?
- asp.net-mvc – IdentityDbContext vs Reb的DbContext
- asp.net-core – 为什么在我的ASP.NET Core 1.0(MVC6)项目中
- asp.net-web-api – 如何在Swashbuckle中替换Swagger UI标题
- Asp.net url路由陷阱asmx web服务调用
- ASP.NET“死亡黄屏”如何显示代码?
推荐文章
站长推荐
热点阅读