Skip to content Skip to sidebar Skip to footer

How To Send Uploaded Excel Files From Javascript To The Controller In Mvc 4

I have a file upload button which can upload multiple files. I want to store these files on to a folder using javascript and send these file details from view to the controller. I

Solution 1:

I use a jquery plugin called Uploadify

HTML:

<input type="file" id="uploadBtn" />

Javascript:

<scripttype='javascript/text'>
$('#uploadBtn').uploadify({
        'uploader': '/uploadify/uploadify.swf',
        'script': 'URL',
        'cancelImg': '/uploadify/cancel.png',
        'buttonText': 'Upload',
        'auto': true,
        'multi': false,
        'removeCompleted': true,
        'simUploadLimit': 1,
        'scriptData': {  },
        'onAllComplete': function () {
           //finished
        }
    });
</script>

MVC ACTION:

publicvoidUploadFile(){
 //Get the file
 HttpPostedFileBase upload = this.Request.Files[0];

 //DO STUFF
}

The url in the javascript method for the parameter 'script' will just be the url to your action. For example if the UploadFile action is in the controller Files then the url will be something like this:

/Files/UploadFile

You can also pass though extra data with 'scriptData' parameter and then just access them the following way

Stringname= Request["name"];

Post a Comment for "How To Send Uploaded Excel Files From Javascript To The Controller In Mvc 4"