This is a migrated thread and some comments may be shown as answers.

How to set initial files from model when using upload tag helper?

5 Answers 386 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Václav
Top achievements
Rank 1
Václav asked on 02 Oct 2018, 09:38 PM

I would like to use the tag helper, but I cannot set the initial files like

<files>@Html.Raw(Model.InitialFiles)</files>

I am only able to set them as static HTML list, i.e.

<files><file name="dummy" size="1024" extension=".ext"/></files>

(https://docs.telerik.com/aspnet-core/tag-helpers/editors/upload/overview)

Is it possible to use the tag helper when the file list would be obtained from a model? And how?

 

5 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 05 Oct 2018, 12:06 PM
Hello Václav,

Thank you for reporting the issue.

I have logged it as a bug and we will do our best to fix it as soon as possible. If you observe any other issue or you have further questions please let me know.

Regards,
Plamen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Chris
Top achievements
Rank 1
answered on 09 Aug 2019, 10:28 PM

Yes, this is not working for me also.  The statement:

.Files(
files =>
                       {
                              files.Add().Name("NAME1").Extension(".jpg").Size(1234);
 
                        }
                        )

 

 

doesn't work.  why not?  Please provide a complete working example with taghelper.  Thanks

0
Ivan Danchev
Telerik team
answered on 14 Aug 2019, 04:43 PM
Hello,

An exemplary .Files configuration of the Upload's taghelper is shown below:
<kendo-upload drop-zone="drop-zone1" name="files">
    <async save-url="save" />
    <files>
        @foreach (var f in Model)
        {
            <file name="@f.Name" extension="@f.Extension" size="@f.Size"></file>
        }
    </files>
</kendo-upload>

The index action returning the viewmodel:
 IList<UploadInitialFile> initialFiles = new List<UploadInitialFile>();
 
public IActionResult Index()
{
    UploadInitialFile file1 = new UploadInitialFile("file1", 1200000, ".jpg");
    UploadInitialFile file2 = new UploadInitialFile("file2", 1400000, ".png");
 
    initialFiles.Add(file1);
    initialFiles.Add(file2);
 
    return View(initialFiles);
}

The view model:
public class UploadInitialFile
{
    public string Name { get; set; }
    public long Size { get; set; }
    public string Extension { get; set; }
 
    public UploadInitialFile(string name, long size, string extension)
    {
        this.Name = name;
        this.Size = size;
        this.Extension = extension;
    }
}


Regards,
Ivan Danchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Chris
Top achievements
Rank 1
answered on 03 Sep 2019, 09:55 PM

For those that are having the same issue, I've created a how to article located here:  Kendo Upload 'Batch Mode'.

There is also source code to download, to get started quickly!

0
Ivan Danchev
Telerik team
answered on 04 Sep 2019, 04:09 PM

Chris,

Thank you for sharing your approach with the community. I am sure it would be helpful to anyone facing a similar scenario.

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Upload
Asked by
Václav
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Chris
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or