Hello,
Are there any examples of using the upload control in the grid? I'm basically looking for functionality that I can use to upload a file, and then view the file after I upload it.
Sort of like the example of the rad upload in ajax grid:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/raduploadinajaxifiedgrid/defaultcs.aspx?product=upload
Thanks for any help.
10 Answers, 1 is accepted
I've uploaded a code library that demonstrates how to use the Upload in Grid.
http://www.telerik.com/community/code-library/aspnet-mvc/upload/upload-in-grid.aspx
I hope this helps.
Tsvetomir Tsonev
the Telerik team
I've updated given sample with insert functionality and can't get it to work:
[HttpPost]
[GridAction]
public
ActionResult Insert()
{
var newModel =
new
Employee();
TryUpdateModel(newModel);
Model =
new
List<Employee>
{
Model.First(),
newModel
};
return
View(
new
GridModel(Model));
}
function
onUpload(e) {
if
(getDataItem(
this
) !== undefined) {
e.data = { id: getDataItem(
this
).ID };
}
else
{
e.data = { id: 0 };
}
}
@(Html.Telerik().Grid<
Employee
>()
.Name("Grid")
.DataKeys(keys => keys.Add("ID"))
.ToolBar(x=>x.Insert())
.Columns(columns =>
{
columns.Bound(c => c.Picture)
.ClientTemplate("<
img
src='/Content/UserFiles/<#= Picture #>' alt='<#= Name #>' />")
.Width(200)
.Title("Picture");
columns.Bound(c => c.Name);
columns.Command(c => c.Edit()).Width(200);
})
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("Select", "Home")
.Update("Update", "Home")
.Insert("Insert", "Home")
)
)
So several things:
1) looks like I can't access getDataItem(this) when inserting, is this by design?
2) When inserting I'm getting error "Error! Upload failed. Unexpected server response - see console." File is actually uploaded, in console i see folowing:
Server response: {"fileName":"Chrysanthemum.jpg"}.
We've updated the code library to include insert functionality. I hope this helps.
All the best,Tsvetomir Tsonev
the Telerik team
Does upload in grid work with MVC3?
Despite applying '[UIHint("Attachment")]' annotation in my ViewModel, during editing/inserting there is no Upload button, just regular textbox. Have I omitted something?
When I had moved necessary files to code library project (MVC2) it worked at once.
Btw, thanks Tsvetomir for updated example.
Let me know if there is any fix otherwise I would appreciate if you have a simple sample illustrating the upload functionaly working upon inserts (and updates) with MVC3... (and razor if possible).
Cheers
/Alejandro
We've downgraded the project to MVC2 in order to lower the requirements for running it. It does not use anything MVC3-specific so upgrading should be trivial.
The code from the code library will work with the Q2 version as well.
I hope this clears things up.
Tsvetomir Tsonev
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
My mistake, I had problems with the action method parameter. I changed it to nullable (Guid?) and now I get the Ajax OnSave call correctly when a file is uploaded... However, while having uploaded a file I am having problems with the TryUpdateModel() in the Insert method. The behaviour is exactly the same as the one described here "http://www.telerik.com/community/forums/aspnet-mvc/upload/upload-control-conflicts-with-updatemodel-mvc-method.aspx"... If I remove the file (by click on the "remove" button and try to insert the row again (this time without the attachment) then the TryUpdateModel() does work (same if I never attach a file).
I see there is a bug fix for this conflict with TryUpdateModel on version 2011.1.419... .however, my version is MVC_2011_2_712-OpenSource using MVC 3... Do you know if that hot-fix was merged on time when the 2011.2.712 version?
Regards
/Alejandro
Hi again Tsvetomir
I found and tried the 295848_Telerik-Extensions-for-ASPNET-MVC-2011-2-829-hotfix version (more recent than 2011.2.712 and 2011.1.419) and now everything works. I guess there were some UpLoad fixes recently.
Best regards.