0

I have an Ajax form, which loads several files; the problem is that Request.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 --%>

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

My form is in a modal dialog, so I can't go back to a Html.BeginForm; the whole point was to perform the edit without a postback. We don't use jQuery form, so I'll give uploadify a try.
Does that means, that if I try to upload a file with a common form, launching a JavaScript function which uses xmlhttp and send a POST with it, i won't be able to do it? =(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.