1

I have an ASP.NET Web API written in MVC. I have a post action with some optional arguments.

public Guid PostExecution(string Action, List<Guid> ComputersIDs, int Port = 0, string Command = null, string Password = null)

It works perfectly. Now I need this action to receive an optional file sent through the post method.

So:

public Guid PostExecution(string Action, List<Guid> ComputersIDs, int Port = 0, string Command = null, string Password = null, HttpPostedFileBase file = null)

The interesting thing is that when I add the parameter HttpPostedFileBase the servers stops the responds the requests to this action and only says Error 500 Internal Server error. It doesn't thrown any exception. With a breakpoint the code doesn't enter to the PostExecution.

Why does this happen?

How can I debug this error?

Is it possible to have an optional HttpPostedFileBase?

ekad
  • 14,436
  • 26
  • 44
  • 46
Ricardo Polo Jaramillo
  • 12,110
  • 13
  • 58
  • 83

1 Answers1

3

all posted files are optional!

and you can get them by Request.Files, and you don't need to have them in methods parameter

Milad Hosseinpanahi
  • 1,495
  • 12
  • 20
  • Explain me a little more please. I used to do something like public ActionResult Index(HttpPostedFileBase file) according to http://stackoverflow.com/a/5193851/909974 – Ricardo Polo Jaramillo Sep 16 '13 at 04:53
  • Well, that is the binding magic of asp.net mvc! but you want to use that when you are certain there will be a file, actually that binding it self gets the files from Request.Files too, and just make the method a little easier to read and follow,if the user does not send any file with that special name (of the input type=file) the action will not be found and 404 error goes back to the client – Milad Hosseinpanahi Sep 16 '13 at 05:00