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

[Solved] multiple upload controls in grid do not work

1 Answer 79 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sorina
Top achievements
Rank 1
Sorina asked on 20 Oct 2011, 09:26 PM
Hi,
I need to have a grid where for each row I should have an upload control.

The code looks like:

 columns.Template(o =>
            {%>
               <%=Html.Telerik().Upload()
               .AssetKey(o.Course.Aktivitetskode)                             
                .Name("attachments")
                .Multiple(true)
                .Localizable("Da")
                .HtmlAttributes(new { @class = "myCustomClass"})               
                .Async(async => async
                    .Save("Save", "Enrollment", new {folderPath = o.Documentation.FolderPath, courseActivityCode=o.Course.Aktivitetskode })
                    .Remove("Remove", "Enrollment", new { folderPath = o.Documentation.FolderPath })
                    .AutoUpload(true)
                )%>
            <% });
The Save method signature looks like:

 public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments, string folderPath, string courseActivityCode)


The upload works fine for the first upload control, but when I press on the second, after I select the files, nothing happens.
I figured out that this is due to the fact that all the controls get generated with the same name and id.
If I change the name of the upload control from .Name("attachments") into .Name("attachments" + counter++), when the save method gets invoked, the attachments is set to null, so I cannot retrieve the files. If I create a Save method for each row, with the first parameter named exactly as each upload control, it works, but I do not have a fixed max number of rows, so this is not a solution.

How shall I implement it to get it working?

Cheers,
Sorina

1 Answer, 1 is accepted

Sort by
0
Gordon
Top achievements
Rank 1
answered on 10 Feb 2012, 01:25 AM
Your problem is the name of the upload control. All your upload controls will have the same name, and therefore the same id, so only the first one will work. You need to change the name of the upload control for each output.

I'm currently stuck trying to do the same thing on editing of a row and having multiple upload fields.
Tags
General Discussions
Asked by
Sorina
Top achievements
Rank 1
Answers by
Gordon
Top achievements
Rank 1
Share this question
or