1

我有一个用 MVC 编写的 ASP.NET Web API。我有一个带有一些可选参数的 post 操作。

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

它完美地工作。现在我需要这个动作来接收通过 post 方法发送的可选文件。

所以:

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

有趣的是,当我添加参数时HttpPostedFileBase,服务器停止响应对此操作的请求,并且只显示错误 500 内部服务器错误。它没有抛出任何异常。使用断点,代码不会进入PostExecution.

为什么会这样?

如何调试此错误?

是否可以有一个可选的HttpPostedFileBase

4

1 回答 1

3

所有发布的文件都是可选的!

并且您可以通过 获取它们Request.Files,并且您不需要将它们包含在方法参数中

于 2013-09-16T04:45:45.770 回答