How to upload files from cell control uploader

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 UploadFiles on file upload

How can I upload one or more files per row with a different id.


1.png

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 UploadFiles, string imgtmp)

{

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




5 Replies

PM Ponmani Murugaiyan Syncfusion Team March 9, 2022 03:38 PM UTC

Hi Demian, 

As per your requirement, you can use the name attribute with same name in all file uploader component. The name attribute must match the name of a parameter in the POST method. For more information, please refer the below documentation. 


Regards, 
Ponmani M 



DE Demian March 9, 2022 10:06 PM UTC

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



PM Ponmani Murugaiyan Syncfusion Team March 11, 2022 02:50 AM UTC

Hi Demian, 

We have prepared sample for your requirement, please find below. 

[Index.cshtml] 
@{ 
    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> 

[ValueController.cs] 
 
public void Save(IList<IFormFile> UploadFiles) 
        { 
            try 
            { 
                foreach (var file in UploadFiles) 
                { 
                    var filename = ContentDispositionHeaderValue 
                                        .Parse(file.ContentDisposition) 
                                        .FileName 
                                        .Trim('"'); 

Regards, 
Ponmani M 



DE Demian March 16, 2022 12:57 AM UTC

thanks it works great




PM Ponmani Murugaiyan Syncfusion Team March 16, 2022 04:23 AM UTC

Hi Demian, 

Welcome, we are glad to hear that the issue has been resolved. 

Regards, 
Ponmani M 


Loader.
Up arrow icon