All of this worked great...thank you.
I have another question. Is there a way to pass data besides the file name to my controller? For example, lets say I want to append some text to my file name in javascript in the file selected event as an identifier and I want to do something with that extra text in my controller in the same action result as my file upload...can this be done?
@Html.EJ().Uploadbox("UploadDefault").SaveUrl("SaveDefault").RemoveUrl("RemoveDefault").ClientSideEvents(e=>e.FileSelect("onselect").Begin("uploadbegin"))
<script>
function onselect(args)
{
for (i = 0; i < args.files.length;i++)
{
args.files[i].name= args.files[i].name + "file" +i
}
}
function uploadbegin(args)
{
args.data= args.files.name
}
</script> |
public ActionResult SaveDefault(IEnumerable<HttpPostedFileBase> UploadDefault , string UploadDefault_data)
{
foreach (var file in UploadDefault)
{
var fileName = Path.GetFileName(file.FileName);
var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
file.SaveAs(destinationPath);
}
ViewData["data"] = UploadDefault_data;
return Content(UploadDefault_data);
} |
I have another question besides the one above. How do I pass something back from within the return Content statement that doesn't result in a red X when the import has completed.I have the following:result = successCount + "_" + failedCount;return Content(result);If I do the above, my upload box shows a red X as if the file failed even though it uploaded correctly.Thanks
@Html.EJ().Uploadbox("UploadDefault").SaveUrl("SaveDefault").ClientSideEvents(e =>e.Begin("uploadbegin").FileSelect("onSelect").Success("onSuccess"))
<script>
var length;
function onSelect(args) {
length = args.files.length;
}
function uploadbegin(args) {
args.data = length
}
function onSuccess(args) {
console.log(args.responseText);
}
</script> |
public ActionResult SaveDefault(IEnumerable<HttpPostedFileBase> UploadDefault, string UploadDefault_data)
{
foreach (var file in UploadDefault)
{
var fileName = Path.GetFileName(file.FileName);
var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
file.SaveAs(destinationPath);
result = UploadDefault_data;
}
ViewData["data"] = UploadDefault_data;
return Content(result);
} |