I have a table in HTML where I assemble a list, in this table at the end in a column I have the uploader control with a different identifier number for each control, but when passing the file from the server side, it reaches zero to the IList
How can I upload one or more files per row with a different id.
Here the html that I have in the cshtml view
@if (ViewBag.datasourceDoc != null)
{
@foreach (var docGrupo in ViewBag.datasourceDoc)
{
}
| @docGrupo.Orden | @docGrupo.Descrip |
|
}
Code in controller:
[AcceptVerbs("Post")]
public IActionResult SaveDoc(IList
{
try
{
string wwwPath = _hostingEnv.WebRootPath;
string contentPath = _hostingEnv.ContentRootPath;
string path = Path.Combine(wwwPath, "Uploads", imgtmp);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (var file in UploadFiles)
{
if (UploadFiles != null)
{
var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
filename = path + $@"\{filename}";
if (!System.IO.File.Exists(filename))
{
using (FileStream fs = System.IO.File.Create(filename))
{
file.CopyTo(fs);
fs.Flush();
}
}
else
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = 404;
Response.Headers.Add("status", "El fichero ya existe.");
}
}
}
}
catch (Exception e)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = 400;
Response.Headers.Add("status", e.Message);
}
return Content("");
}
thanks
I don't fully understand how to do it, I already checked the link, but it comes in javascript I'm working with aspnet core
I make the post call by ajax
Thank you
|
@{
var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "api/Values/Save", RemoveUrl = "api/Values/Remove" };
}
<ejs-uploader name="uploadFiles" id="uploadFiles1" asyncSettings="@asyncSettings" autoUpload="false"></ejs-uploader>
<ejs-uploader name="uploadFiles" id="uploadFiles2" asyncSettings="@asyncSettings" autoUpload="false"></ejs-uploader>
<ejs-uploader name="uploadFiles" id="uploadFiles3" asyncSettings="@asyncSettings" autoUpload="false"></ejs-uploader>
<ejs-uploader name="uploadFiles" id="uploadFiles4" asyncSettings="@asyncSettings" autoUpload="false"></ejs-uploader> |
|
public void Save(IList<IFormFile> UploadFiles)
{
try
{
foreach (var file in UploadFiles)
{
var filename = ContentDispositionHeaderValue
.Parse(file.ContentDisposition)
.FileName
.Trim('"'); |
thanks it works great