ASP.NET MVC中的可选HttpPostedFileBase

问题描述 投票:1回答: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

c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 asp.net-web-api
1个回答
3
投票

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

你可以通过Request.Files获得它们,而且你不需要在methods参数中使用它们

© www.soinside.com 2019 - 2024. All rights reserved.