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

[Solved] Datakey null on ajax delete

3 Answers 193 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.
Pierre-Andre van Leeuwen
Top achievements
Rank 1
Pierre-Andre van Leeuwen asked on 10 May 2010, 08:55 AM
Hi

I have a grid that is is Ajax bound. I did this so that I could use the OnRowDataBound event to enable/disable the edit and delete buttons based on certain criteria. This works as expected. The problem is that the delete command does not work when using only Ajax binding. The delete action looks like this:

[HttpPost]  
[GridAction]  
public ActionResult RemoveActivity(Guid activityId)   
{  
...  
However, when called, I get a javascript syntax error in terlerik.grid.min.js:

success

:b.proxy(function(g){g=eval("("+g+")");

Changing the parameter to Guid ?activityId, doesn't cause the javascript error, but the parameter is then always null.

If I change the grid to use server binding, the delete works, but the OnRowDataBound event is not called.
My grid definition looks like this:

 

<%  
    Html.Telerik().Grid<ActivityModel>()  
                      .Name("CurrentActivitiesGrid")  
                      .Scrollable(scrolling => scrolling.Height(300))  
                      .DataKeys(keys => keys.Add(a => a.ActivityId))  
                      .DataBinding(dataBinding => 
                        dataBinding.Ajax()  
                        .Enabled(true)  
                        .Select("LoadActivities", "EngagementPlanning")  
                        .Update("UpdateActivity", "EngagementPlanning")  
                        .Delete("RemoveActivity", "EngagementPlanning")  
                        )  
 
                      .Columns(columns => 
                        {  
                          columns.Command(commands => 
                          {  
                            commands.Edit();  
                            commands.Delete();  
                                                    }).Width(200).Visible((Boolean)ViewData["AllowEdit"]);  
                          columns.Bound(a => a.ActivityId).Visible(false);  
                          columns.Bound(a => a.ActivityName).Title("Name");  
                        })  
                                            .ClientEvents(events => 
                                                            {  
                                                              events.OnError("OnGridError");  
                                                              events.OnRowDataBound("OnActivityRowBound");  
                                                              events.OnLoad("OnActivityGridLoaded");  
                                                            })  
                      .Footer(false)  
                      .Render();  
  %> 

3 Answers, 1 is accepted

Sort by
0
Pierre-Andre van Leeuwen
Top achievements
Rank 1
answered on 10 May 2010, 09:26 AM
I seem to have found the solution: The action method's parameter must be called id and nothing else.
0
Accepted
Atanas Korchev
Telerik team
answered on 10 May 2010, 09:32 AM
Hello Pierre-Andre van Leeuwen,

Yes, by default the data key parameter is called "id". You can customize that when defining your data key:

DataKeys(keys => keys.Add(o => o.ActivityID).RouteKey("activityId"))

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
iConect Developer - Mike
Top achievements
Rank 1
answered on 18 Nov 2011, 01:54 AM
By the way since this confused me when looking at the answer this is what he meant to fix it:

[HttpPost] 
[GridAction] 
public ActionResult RemoveActivity(Guid id)  
... 
}

or you can use the RouteKey thing the telerik people posted
Tags
Grid
Asked by
Pierre-Andre van Leeuwen
Top achievements
Rank 1
Answers by
Pierre-Andre van Leeuwen
Top achievements
Rank 1
Atanas Korchev
Telerik team
iConect Developer - Mike
Top achievements
Rank 1
Share this question
or