I am uploading a file in my ASP.NET MVC application using Uploadify.
Controller:
public ActionResult Upload(HttpPostedFileBase file)
{
List<string> validIDs, invalidIDs;
if (file.ContentLength > 0)
{ //do something
}
}
Uploadify code (in a .ascx file):
$(document).ready(function () {
$("#file_upload").uploadify({
'uploader': '/Scripts/uploadify/uploadify.swf',
'script': '/XYZ/Upload',
'cancelImg': '/Scripts/uploadify/cancel.png',
'fileExt': '*.jpg;*.gif;*.png;*.bmp;*.htm;*.html;*.zip',
'fileDesc': '*.jpg;*.gif;*.png;*.bmp;*.htm;*.html;*.zip',
'auto': true,
'multi': false,
'sizeLimit': 1048576, //1 MB
'buttonText': 'Upload Files'
}
});
});
The 'file' in the controller action is always returning NULL. What am I missing?
Replace:
public ActionResult Upload(HttpPostedFileBase file)
with:
public ActionResult Upload(HttpPostedFileBase fileData)
Uploadify
uses the fileData
name by default. You could change that in the settings if you want like that: fileDataName: 'file'
. Take a look at the following post as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With