views:

136

answers:

1

i have a file in my view

<form id="upload" enctype="multipart/form-data">
<input type="file" name="fileUpload" id="fileUpload" size="23" /><br />
</form>

and an ajax request

$.ajax({
                url: '<%=Url.Action("JsonSave","Survey")  %>',
                dataType: 'json',
                processData: false,
                contentType: "multipart/mixed",
                data:
                 {
                     Id: selectedRow.Id,
                     Value: 'some date was added by the user here :))'
                 },
                cache: false,
                success: function(data) {
                }
            });

but there is no file in the Request.Files. Whats wrong with the ajax request?

+2  A: 

You can't upload files via ajax, you need to use an iFrame or some other trickery to do a full postback. This is mainly due to security concerns.

Here's a decent write-up including a sample project using SWFUpload and ASP.Net MVC by Steve Sanderson. It's the first thing I read getting this working properly with Asp.Net MVC (I was new to MVC at the time as well), hopefully it's as helpful for you.

Nick Craver
+1 damn I need more votes!
Anurag