Currently I'm working with image uploading using MVC3. When I did some searches for sample code I found out several approaches. I figured out almost 3 methods. Can someone explain which one is better over the other or all of them are the same? An explanation when it comes to performance or anything is welcome.

Method 1: As parameter

public ActionResult UploadImage(HttpPostedFileBase img)
        {

            return View();
        }

Method 2: From Request.Files

HttpPostedFileBase imgFile= Request.Files["img"];

Method 3: From Image Helper

var imgFile= WebImage.GetImageFromRequest();
有帮助吗?

解决方案

The first is the best approach. The reason for that is because this will make the action easier to unit test and it doesn't rely on magic strings.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top