简体   繁体   中英

Optional HttpPostedFileBase in ASP.NET MVC

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 ?

all posted files are optional!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM