Question

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();
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top