Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET MVC中的可选HttpPostedFileBase_C#_Asp.net Mvc_Asp.net Mvc 4_Asp.net Mvc 3_Asp.net Web Api - Fatal编程技术网

C# ASP.NET MVC中的可选HttpPostedFileBase

C# ASP.NET MVC中的可选HttpPostedFileBase,c#,asp.net-mvc,asp.net-mvc-4,asp.net-mvc-3,asp.net-web-api,C#,Asp.net Mvc,Asp.net Mvc 4,Asp.net Mvc 3,Asp.net Web Api,我有一个用MVC编写的ASP.NETWebAPI。 我有一个带有一些可选参数的post操作 public Guid PostExecution(string Action, List<Guid> ComputersIDs, int Port = 0, string Command = null, string Password = null) public Guid执行后(字符串操作,列表计算机SID,int-Port=0,string-Command=null,string-Pa

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

public Guid PostExecution(string Action, List<Guid> ComputersIDs, int Port = 0, string Command = null, string Password = null)
public Guid执行后(字符串操作,列表计算机SID,int-Port=0,string-Command=null,string-Password=null)
它工作得很好。现在,我需要此操作来接收通过post方法发送的可选文件

因此:

公共Guid执行后(字符串操作、列表计算机SID、int-Port=0、字符串命令=null、字符串密码=null、HttpPostedFileBase文件=null)
有趣的是,当我添加参数
HttpPostedFileBase
时,服务器停止响应此操作的请求,并且只显示Error 500 Internal Server Error。它不会引发任何异常。使用断点时,代码不会进入
执行后

为什么会发生这种情况

如何调试此错误


是否可以有一个可选的
HttpPostedFileBase

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


您可以通过
Request.Files
获取它们,您不需要将它们放在方法参数中,请再解释一下。我曾经做过类似于PublicActionResult索引(HttpPostedFileBase文件)的事情,这就是asp.NETMVC的绑定魔法!但是,当您确定将有一个文件时,您希望使用该方法,实际上绑定它本身也会从Request.files获取文件,并且只是使该方法更易于阅读和遵循,如果用户不发送任何具有该特殊名称(输入类型=file)的文件,则将找不到该操作,404错误将返回到客户端
public Guid PostExecution(string Action, List<Guid> ComputersIDs, int Port = 0, string Command = null, string Password = null, HttpPostedFileBase file = null)