我有一个有3个文件输入的网页。当用户上传文件时,表单上有特定字段需要发送。我无法弄清楚如何将自定义数据添加到我的POST以及如何在服务器上检索它。这就是我的代码的样子:
ASPX页面,包含3个文件输入和其他文本框/下拉列表:
<form action="FilesUploader.ashx" method="post">
<div id="dvNewAttachment1">
<span>Attachment Type</span>
<select id="ddlAttachmentType1">
<option>T1</option>
<option>T2</option>
<option>T3</option>
</select>
<span>Description</span>
<input id="txtDesc1" />
<select id="ddlApproval1">
<option>Yes</option>
<option>No</option>
</select>
<input id="fileUploader1" type="file" runat="server" />
</div>
<br />
---------------
<div id="dvNewAttachment2">
<span>Attachment Type</span>
<select id="ddlAttachmentType2">
<option>T1</option>
<option>T2</option>
<option>T3</option>
</select>
<span>Description</span>
<input id="txtDesc2" />
<select id="ddlApproval2">
<option>Yes</option>
<option>No</option>
</select>
<input id="fileUploader2" type="file" runat="server" />
</div>
<br />
-------------------------------
<div id="dvNewAttachment3">
<span>Attachment Type</span>
<select id="ddlAttachmentType3">
<option>T1</option>
<option>T2</option>
<option>T3</option>
</select>
<span>Description</span>
<input id="txtDesc3" />
<select id="ddlApproval3">
<option>Yes</option>
<option>No</option>
</select>
<input id="fileUploader3" type="file" runat="server" />
</div>
<input type="submit" />
</form>
这就是我的处理程序的样子:
public void ProcessRequest(HttpContext context)
{
HttpPostedFile myFile = context.Request.Files[0];
int nFileLen = myFile.ContentLength;
byte[] buffer = new byte[nFileLen];
using (BinaryReader br = new BinaryReader(myFile.InputStream))
{
br.Read(buffer, 0, buffer.Length);
}
}
正如您所看到的,我有3个上传,每个都有与之关联的附件类型和描述,我需要为我的处理程序中的每个输入文件检索。
现在我只是从第一个输入处理文件,但后来我将通过输入循环并处理它们。
答案 0 :(得分:0)
如果你的处理程序没有收到你放在文件上传者中的文件,那么你的表单需要有这样的附加属性:
<form action="FilesUploader.ashx" method="post" enctype="multipart/form-data">
要从服务器上的下拉列表中获取值,您需要为其提供name
属性:
<select id="ddlApproval1" name="ddlApproval1">
<option>Yes</option>
<option>No</option>
</select>