Ajax form doesn't load files
I have an Ajax form, which loads several files; the problem is that Req开发者_StackOverflow社区uest.Files
is always empty. I couldn't find anything about it, so here it is.
<%using (Ajax.BeginForm("Edit", "Manage", FormMethod.Post,
new AjaxOptions{ OnComplete = "OnSaveEditSuccess" },
new { enctype="multipart/form-data", id = "form_Edit", name = "form_Edit" }))
{%>
/* ... */
<input type="file" id="CCTranscripts_fileId" name="CCTranscripts_fileId"
onchange="ValidateUploadFile('CCTranscripts_file', this.value);" />
/* ... */
<% } %> <%-- end form --%>
You cannot upload files using an AJAX Form. In order to upload files you need to use a normal Html.BeginForm
. This is because when an AJAX request is sent the multipart/form-data
is no longer respected. Also using javascript you cannot access the file contents in order to send it to the server. There are some plugins which allow you to achieve this. For example the jquery form plugin supports AJAX uploads by generating a hidden iframe. Uploadify is another popular plugin which uses Flash.
精彩评论