How do I cast from System.Web.HttpPostedFileBase to System.Web.HttpPostedFile?

前端 未结 2 568
渐次进展
渐次进展 2021-02-19 12:56

While trying to implement an MVC file upload example on Scott Hanselman\'s blog. I ran into trouble with this example code:

foreach (string file in Request.Files         


        
2条回答
  •  无人共我
    2021-02-19 14:00

    Just work with it as an HttpPostedFileBase. The framework uses the HttpPostedFileWrapper to convert an HttpPostedFile to an object of HttpPostedFileBase. HttpPostedFile is one of those sealed classes that are hard to unit test with. I suspect that sometime after the example was written they applied the wrapper code to improve the ability to test (using HttpPostedFileBase) controllers in the MVC framework. Similar things have been done with the HttpContext, HttpRequest, and HttpReponse properties on the controller.

提交回复
热议问题