I'm using uploadify
fileupload plugin for my MVC3 project.
I'm trying to use the uploading file to the controller.
How do i use multi file upload and single file upload together ?
I know to use IEnumerable<HttpPostedFileBase> files
for multiple files and HttpPostedFileBase files
for single file upload. How to combine these.
In my project, the user may select multiple files or only a single file to upload it to the controller.
so, if i use IEnumerable<HttpPostedFileBase> files
in my controller action, i'm unable to get single files(files is null) and if i use HttpPostedFileBase files
it doesnot show anything, files is always null here.
How to get work with single file upload, i can get the multiple file uploads but not the single files.
How to get this work ?
Here is my code:
HTML
<body>
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div id="fileupload" style="display:none">
<div style="clear: none;">
File to Upload:
<input type="file" name="file_upload" id="file_upload" style="padding-left: 50px;"/><hr />
</div>
<p style="text-align: right;">
<input type="submit" id="selectimage" value="Ok" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"/>
<input type="submit" id="cancelimage" value="Cancel" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="cancelupload();" />
</p>
</div>
<input type="button" id="btnImg" />
<div id="filecontent">
Added Images:
</div>
}
</body>
<script>
$(function(){
$('#file_upload').uploadify({
'checkExisting': 'Content/uploadify/check-exists.php',
'swf': '/Content/uploadify/uploadify.swf',
'uploader': '/Home/Index',
'auto': false,
'buttonText': 'Browse',
'fileTypeExts': '*.jpg;*.jpeg;*.png;*.gif;*.zip',
'removeCompleted': false,
'onSelect': function (file) {
$("#selectimage").click(function () {
$("#file_upload-queue").appendTo("#filecontent");
});
}
});
});
</script>
Controller Action
public ActionResult Index(IEnumerable<HttpPostedFileBase> fileData)
{
foreach (var file in fileData)
{
if (file.ContentLength > 0)
{
string currpath = Server.MapPath("~/Images/");
currpath = Path.Combine(Server.MapPath("~/Images/Admin"), file.FileName);
file.SaveAs(currpath);
}
}
return View();
}
What should i change in controller action to get single file upload and multi file upload to work?
Update
Neither IEnumerable<HttpPostedFileBase> fileData
nor HttpPostedFileBase fileData
working