File upload returns null

I upload a file to my ASP.NET MVC application using the Download program.

Controller:

public ActionResult Upload(HttpPostedFileBase file)
        {           
            List<string> validIDs, invalidIDs;
            if (file.ContentLength > 0)
            { //do something
            }
        }

Download code (to .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'
}
    });
});

A “file” in a controller action always returns NULL. What am I missing?

+5
source share
1 answer

Replace:

public ActionResult Upload(HttpPostedFileBase file)

with:

public ActionResult Upload(HttpPostedFileBase fileData)

Uploadifydefault name is used fileData. You can change this in the settings if you want to: fileDataName: 'file'. Take a look at the next post .

+6
source

All Articles