0

I have done a deep research trying to find the more pratical way to upload files from the client-side and I decided to go for the input type file html element.

Problem is: I get nothing in the controller and I am not able to see even the fakepath string been set in firebug.

View:

<form action="action" id="id" method="POST" enctype="multipart/form-data">
    <table id="tblId">            
        <tr>
            <td><input type="file" name="file" /></td>
        </tr>
    </table>
    <input type="submit" value="import" />
</form>   

As you can see, I am properly using enctype. Data is been sent to the controller as it should except that there is no data.

Controller:

[HttpPost]
public ActionResult opImportFile(FormCollection form) {


    var file = Request.Files["file"];
        if (file != null)
        {
            return Content("ok");
        }
        else
        {
            return Content("bad");
        }
}

And I am getting always "bad"! Too bad. Is there any other way I could try or am I doing somenthing wrong?

P.S -> It is a ajax request:

$('#formUpdStoringSettings').submit(function (e) {

    e.preventDefault();    
    var form = $(this);       
    alert($('input[name=file]').val()); //Here I am able to get the fakepath...
    alert(form.serialize());  //Here I get nothing...

    $.ajax({
        url: form.attr('action'),
        type: form.attr('method'),
        data: form.serialize(),
        success: function (response) {
        }
   });
}
4
  • 1
    Have you seen this? You may need to use FormData() stackoverflow.com/questions/2320069/… Commented Jan 29, 2013 at 19:50
  • 1
    You probably will need to use a jQuery plug-in to be able to upload using AJAX. blueimp.github.com/jQuery-File-Upload Commented Jan 29, 2013 at 19:53
  • Thanks... ajax was the problem Commented Jan 29, 2013 at 20:03
  • @QuetiMporta Anwser this question so I can provide you some reputation. Commented Jan 30, 2013 at 13:29

1 Answer 1

1

You probably will need to use a jQuery upload plug-in to be able to upload using AJAX.

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

1 Comment

I am trying uploadify. Just modified upload.php to upload.cs but it still not working. HTTP ERROR(404). Discussion: stackoverflow.com/questions/14609590/…

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.