<code>
@Html.EJ().Uploadbox("UploadDefault").SaveUrl("SaveDefault").RemoveUrl("RemoveDefault").AsyncUpload(false)
@Html.EJ().Button("btnclick").Type(ButtonType.Button).Text("Click")
</code> |
<code>
<script type="text/javascript">
$(function () {
$("#btnclick").click(function (args) {
var formdata = new FormData();
var _files = $("[name='UploadDefault']:not(.e-uploadinput)")[0].files.length;
for (var x = 0; x < _files; x++) {
formdata.append("fileInput[" + x + "]", $("[name='UploadDefault']:not(.e-uploadinput)")[0].files[x]);
}
$.ajax
(
{
url: '@Url.Action("SaveSynchronous", "FileUpload")', //'/Tab/QuickListTabContent',
type: 'POST',
data: formdata,
processData: false,
contentType: false,
cache: false,
}).done(function (result) {
$("[name='UploadDefault']:not(.e-uploadinput)").each(function () {
$(this).remove();
});
var inst = $("#UploadDefault").ejUploadbox("instance");
inst.updialog.data('ejDialog').close();
}
);
});
});
</script>
</code> |
<code>
Controller
[HttpPost]
public ActionResult SaveSynchronous(IEnumerable<HttpPostedFileBase> fileInput)
{
if (fileInput != null)
{
foreach (var file in fileInput)
{
var fileName = Path.GetFileName(file.FileName);
var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
file.SaveAs(destinationPath);
}
TempData["status"] = "Successfully Uploaded";
return RedirectToAction("FileUploadFeatures");
}
else
{
TempData["status"] = "Select a file to upload";
return RedirectToAction("FileUploadFeatures");
}
}
</code> |
<code>
$(function () {
$("#btnclick").click(function (args) {
var formdata = new FormData();
var _files = $("[name='UploadDefault']:not(.e-uploadinput)")[0].files.length;
for (var x = 0; x < _files; x++) {
formdata.append("fileInput[" + x +"]", $("[name='UploadDefault']:not(.e-uploadinput)")[0].files[x]);
}
formdata.append("idConflicto", "1");
$.ajax
(
{
url:'@Url.Action("SaveSynchronous", "FileUpload")',
type: 'POST',
data: formdata,
processData: false,
contentType: false,
cache: false,
}).done(function(result) {
$("[name='UploadDefault']:not(.e-uploadinput)").each(function() {
$(this).remove();
});
var inst = $("#UploadDefault").ejUploadbox("instance");
inst.updialog.data('ejDialog').close();
}
);
});
});
</script>
// Controller
public ActionResultSaveSynchronous(IEnumerable<HttpPostedFileBase> fileInput,String idConflicto)
{
}
</code> |