ASP.NET MVC Ajax Form: Is enctype correct? Why doesn't file get uploaded?

Posted by Fabio Milheiro on Stack Overflow See other posts from Stack Overflow or by Fabio Milheiro
Published on 2009-09-17T00:23:06Z Indexed on 2010/04/28 3:33 UTC
Read the original article Hit count: 611

In the case that the user doesn't have Javascript activated, in order to draw a form, I begin this way:

<% using (Html.BeginForm("Create", "Language", FormMethod.Post,
    new {enctype="multipart/form-data"}))
{ %>

If the user has Javascript activated, the following code is used:

<% using (Ajax.BeginForm("Create", "Language",
    new AjaxOptions { UpdateTargetId = "CommonArea" },
    new { enctype = "multipart/form-data" }))
{ %>

The problem is this:

In the first case, I can get the file uploaded using the following instruction in the business layer:

// Get the uploaded file
HttpPostedFile Flag = HttpContext.Current.Request.Files["Flag"];

In the second case, this instruction doesn't work. How do I know upload that file using the Ajax.BeginForm? Is the code right? Can anyone more experience advise about using jQuery plug-in to upload file before the form submission?

Thank you

© Stack Overflow or respective owner

Related posts about fileupload

Related posts about file-upload