I'm trying to implement an upload into a window.
this is a code
<!-- >> IMPORT EXCEL-->@{Html.Kendo().Window() .Name("importExcelFileWindow") .Title("Importa file Excel") .Width(500) .Height(300) .Content(@<text> @using (Html.BeginForm("ImportExcelFile", "UploadContacts", FormMethod.Post)) { @(Html.Kendo().Upload() .Name("excelFiles") .Validation(v=>v.AllowedExtensions(new string[] { ".xlsx", ".xls" })) .Async(a => a .Save("Async_Save", "UploadContacts") .Remove("Async_Remove", "UploadContacts") .AutoUpload(true) ).Events(e=>e.Error("uploadError")) ) } </text>).Visible(false).Render();}<script>
function uploadError(e) {
alert(e.XMLHttpRequest.response);
}
[...]
<!-- << IMPORT EXCEL-->
this is a controller
public class AsyncUploadContactsController : Controller { public IWebHostEnvironment HostingEnvironment { get; set; } public string incomingFolder { get; set; } private readonly BusinessDbContext _context; public AsyncUploadContactsController(IWebHostEnvironment hostingEnvironment, BusinessDbContext context) { HostingEnvironment = hostingEnvironment; _context = context; incomingFolder = "App_Data"; } [HttpPost] public ActionResult ImportExcelFile() { return View(); } public async Task<ActionResult> Async_Save(IEnumerable<IFormFile> files) { if (files != null) { foreach (var file in files) { var fileContent = ContentDispositionHeaderValue.Parse(file.ContentDisposition); var fileName = Path.GetFileName(fileContent.FileName.ToString().Trim('"')); var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, incomingFolder, fileName); using (var fileStream = new FileStream(physicalPath, FileMode.Create)) { await file.CopyToAsync(fileStream); } } } // Return an empty string to signify success return Content(""); } public ActionResult Async_Remove(string[] fileNames) { // The parameter of the Remove action must be called "fileNames" if (fileNames != null) { foreach (var fullName in fileNames) { var fileName = Path.GetFileName(fullName); var physicalPath = Path.Combine(HostingEnvironment.WebRootPath, incomingFolder, fileName); if (System.IO.File.Exists(physicalPath)) System.IO.File.Delete(physicalPath); } } // Return an empty string to signify success return Content(""); } }
when I open the window and I try to upload a file, I obtain this effect (attached screen-shots)
The strange thing is that if I set a breakpoint into actions, I notice that it doesn't go into an action AsynchSave.
I create App_Data folder into wwwroot node's project (is it corrects?
Where I wrong?
