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

前端 未结 2 547
渐次进展
渐次进展 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 13:43

    The correct type to use is HttpPostedFileBase.

    HttpPostedFileBase hpf = Request.Files[file];
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题