enter code here
我想用FileUpload Control上傳文件。由於在我的表單中有太多的複雜性,我不能使用Html.BeginForm(當然這很好)。我想要做的就是使用Input id調用發送文件到控制器的函數。我在網上搜索,但我的需要是這樣的。我不想提交整個表格。我想要做的就是上傳文件並復原到我的表單以完成剩餘的字段。任何類型的代碼片段將不勝感激。由於ASP.NET MVC2中的FileUpload控件C#
下面是代碼示例我有什麼
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
ViewReportFiles
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm([ActionName], [ControllerName], FormMethod.Post, new { target = "_blank" }))
{%>
Here I have few fields to process.
Along with this I have fileUpload control
<table>
<tr>
<td valign="bottom">
<input type="file" id="document" name="document" accept="text/xml, text/csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" size="76" />
</td>
<td valign="bottom">
<div Id="UploadFile"> <input type="image" alt="upload file" src="<%= ResolveUrl("~/media/form_upload_btn.png") %>" name="image" /> </div>
</td>
</tr>
</table>
<% }>
My javascript is as follows
<script type="text/javascript" language="javascript">
$("#UploadFile").click(function() {
if ($("#document").val() == '') {
// checking for selected file
alert('Please select a document.');
return false;
}
$.ajaxFileUpload({
**url: '<%= Url.Action("actionName", "Controller") %>',**
data: { val: 'aaa' },
secureuri: false,
fileElementId: 'document',
dataType: 'xml',
success: function (data) {
}
});
});
</script>
Here the problem is it's not getting into that URL. it goes to my HTTPPost of the page.
My controller code is like this....
public void UploadAccessDataFile(){
foreach (string uploadFile in Request.Files)
{
}
}
Please help.
您正在尋找**異步**使用** AJAX **將文件發送到服務器。 – Amy