哪个FIle表单字段用于C#Request.Files [n] .FileName

Chr*_* C. 1 html c# file-type

如果我有一个包含多个输入文件字段的HTML表单(其中"N"是唯一的数字);

<input type="file" name="inputFileN"> 
Run Code Online (Sandbox Code Playgroud)

然后在C#代码中;

string inFile = System.IO.Path.GetFileName(Request.Files[M].FileName)
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以确定请求数据中'M'的值,以便我可以匹配特定的HTML输入文件类型字段?

在这种情况下,最终用户可以更新编辑表单上的字段,并且除了文件类型字段之外,它适用于所有字段类型.

Man*_*rse 6

所有必要的数据都在HttpContext.Request.Files; 具体来说,在HttpContext.Request.Files.AllKeys:

//HttpContext is a member of `System.Web.Mvc.Controller`,
//accessible in controllers that inherit from `System.Web.Mvc.Controller`.
System.Web.HttpFileCollectionBase files = HttpContext.Request.Files;
string[] fieldNames = files.AllKeys;
for (int i = 0; i < fieldNames.Length; ++i)
{
    string field = fieldNames[i]; //The 'name' attribute of the html form
    System.Web.HttpPostedFileBase file = files[i];
    string fileName = files[i].FileName; //The path to the file on the client computer
    int len = files[i].ContentLength; //The length of the file
    string type = files[i].ContentType; //The file's MIME type
    System.IO.Stream stream = files[i].InputStream; //The actual file data
}
Run Code Online (Sandbox Code Playgroud)