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

Update grid after file upload

2 Answers 367 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carl Nelson
Top achievements
Rank 1
Carl Nelson asked on 10 Dec 2012, 05:31 PM
How do I refresh a grid to reflect a new row after uploading a file? I have a file upload control and a grid control. The rows in the grid are made up of data from files in a folder on the server, such as the file names. The data is gathered into a view model and passed to the form. When a new file is uploaded, I would like to update the grid. I can update the model in the controller code, but I can't pass the updated model back to the view, as the only valid ActionResult for Upload's Save server method is Content(string.Empty). Back in the onSuccess() client function in the view, I have tried this:

var grid = $("ReportGrid").data("tGrid");
grid.rebind();

but nothing happens. I suspect this is because the model hasn't changed on the client.

So how do I "tell" the client grid to add the new row (at the top)? While I'm at it, it would be nice to also clear out the file from the upload display once it is uploaded. That is, I want to remove the shaded box with the green dot showing the file name after upload and instead only show the file in the updated grid.

Incidently, I do not allow multiple file uploads in this application.

Thanks,
Carl

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 13 Dec 2012, 04:49 PM
Hello Carl,

You could return the new collection as JSON from the Upload save action and bind it to the Grid in the OnSuccess event with the dataBind method. Information about returning metadata is available in this documentation topic.
The rebind method should also work if the new data is returned from the Select action and there are not any known reasons that would cause a problem with the method.

Kind regards,
Daniel
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Hetal
Top achievements
Rank 1
answered on 21 Dec 2012, 09:28 AM
you can try this...

var fileUpload = $("#FileUpload").data('tUpload');
 
fileUpload.async.saveUrl = "@Url.Action("Action name", "Controller name")";

after successful upload you can call method which performs select operation...
Tags
Grid
Asked by
Carl Nelson
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Hetal
Top achievements
Rank 1
Share this question
or