Bind Upload widget to Model Property - ASPNET CORE MVC - UPLOAD

1 Answer 975 Views
Grid Upload
Dan
Top achievements
Rank 1
Veteran
Dan asked on 10 Jun 2021, 07:15 PM

I have a grid that is using a custom editor template (pop up). I would like when a user is ready to create a new entry, they have the choice to upload a list of files as well.

In my custom editor I have this:

 @(Html.Kendo().Upload()
            .Name("files")
            .HtmlAttributes(new { aria_label = "files" })
        )

In my Grid model, it has a member that looks like this: (Entry is the class name)

public IEnumerable<IFormFile> files {get;set;}

And my controller signature looks like this :

public ActionResult Create_Entry(Entry entry, [DataSourceRequest] DataSourceRequest request)

However Entry.files is always null. I cant seem to get the file upload widget to bind to that mode property?

I have tried adding an extra parameter for files in the controller params but that doesnt work either.

Any help is appreciated.

 

 

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 15 Jun 2021, 08:49 AM

Hello Dan,

We have a knowledgebase article discussing the issue. You can review it here:

https://docs.telerik.com/aspnet-core/knowledge-base/grid-editing-upload-in-popup

Let me know if the suggested approach works for you.

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Dan
Top achievements
Rank 1
Veteran
commented on 15 Jun 2021, 07:10 PM

Alek, so I have the widget hitting the backend now. However is it possible to submit this with the rest of the pop up custom editor? When the files are chosen it hits an action but it doesnt bind the rest of my model so I cant do anything with the files. This is on a create, so I wont have the ID of the entry until after it has been inserted into the database, then at this point I would use the returned ID to store my file(s). When I make the .Save method use the same action / controller as the form submit it throws an illegal invocation.
Aleksandar
Telerik team
commented on 18 Jun 2021, 12:30 PM

Dan, the Grid works with AJAX requests rather than forms. On the other hand, the upload sends an HttpRequest of type FormData. The two types are conflicting and cannot be merged into a single request automatically. 

Consider using the Upload as a standalone component that is separate from the create/update of the grid. The approach  is demonstrated in the example linked in the initial answer where the Upload is configured in Async mode, and the success handler ensures that the Grid column template will reflect the change.

Tags
Grid Upload
Asked by
Dan
Top achievements
Rank 1
Veteran
Answers by
Aleksandar
Telerik team
Share this question
or