我想使用ImageResizer(从ImageResizing点网)。我通过NuGet为MVC安装ImageResizer。但是当我去使用下面的代码从示例:
//Loop through each uploaded file foreach (string fileKey in HttpContext.Current.Request.Files.Keys) { HttpPostedFile file = HttpContext.Current.Request.Files[fileKey]; if (file.ContentLength <= 0) continue; //Skip unused file controls. //The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details. //Destination paths can have variables like <guid> and <ext>,or //even a santizied version of the original filename,like <filename:A-Za-z0-9> ImageResizer.ImageJob i = new ImageResizer.ImageJob(file,"~/uploads/<guid>.<ext>",new ImageResizer.ResizeSettings( "width=2000;height=2000;format=jpg;mode=max")); i.CreateParentDirectory = true; //Auto-create the uploads directory. i.Build(); }
foreach中的“HttpContext.Current.Request.Files.Keys”不能解析?我有我的正确使用和Visual Studio不提供“Resolve”选项。
解决方法
问题是Controller类有一个名为HttpContext的公共属性(见
http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.httpcontext.aspx)。
这意味着,当您尝试在控制器中使用它而没有任何限定时,它将解析为本地属性,而不是System.Web.HttpContext。属性的类型是HttpContextBase,它有一个Request属性,它会做你想要的(但请注意,它不是你从System.Web.HttpContext得到的相同的类。