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

[Solved] Inconsistency in AJAX binding for update/delete

3 Answers 159 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
Top achievements
Rank 1
Carl asked on 15 Apr 2011, 06:24 PM
Using AJAX binding in a Razor view for a grid with
.DataKeys(key => key.Add(row => row.ResourceIidKey))
.DataBinding(db => db.Ajax()
    .Select("SelectNexusResourcesForEdit", PdsController)
    .Insert("InsertNexusResource", PdsController)
    .Update("UpdateNexusResource", PdsController)
    .Delete("DeleteNexusResource", PdsController)
)

I had success following the pattern explained in the Telerik Help documents for AJAX editing which used the route with optional id parameter and matching id parameter in the action methods for update and delete.

I then attempted to discover whether there was something "magic" (required?, hidden?) about the use of the id parameter. So I changed the id parameter in the route and in the action methods to use a myResourceId parameter. It worked fine without problem for the update method. But NOT for the delete method.

I tried a lot of different approaches to get the delete method to work using my own choice of parameter (the "myResourceId" instead of the "id") and never found a way to get it to work for the delete method. In my opinion, this discrepancy between being able to choose my own parameter for the update method (where it worked great) but not for the delete method (where it failed no matter what I tried) represents a definite form of bug... because this kind of inconsistency (within the MVC paradigm that promotes convention and consistency) causes confusion for developers.... and I lost a lot of time trying to figure this one out.

I hope that Telerik will be able to confirm this inconsistency and eliminate it from the grid. Meanwhile, I will use the "id" parameter for the delete methods. But then to maintain consistency with my update methods, I will also have to use the "id" parameter there as well.

Now as for the reason why I wanted to change the name of the id parameter. That's because I am using nested grids in a hierarchy, and I wanted greater clarity about which id for which level of the hierarchy...

so this whole problem remains to be solved... and it would be nice to see a working demo of a hierarchical grid with AJAX binding where the developer can use their own choice of key parameters that can be used in the routes and action methods for update/delete for each level of the hierarchy.

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Apr 2011, 07:35 AM
Hi Carl,

 By default the DataKey is sent as "id". You can easily change that like this:

.DataKeys(keys => keys.Add(c => c.Field1).RouteKey("myRouteValue"))
The default value for RouteKey is "id" because this is the default parameter name in the default ASP.NET MVC route.
routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

All the best,
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
Carl
Top achievements
Rank 1
answered on 18 Apr 2011, 06:16 PM
Thanks for explaining how .RouteKey() solves this problem.

When I last worked with the grid for RadControls for AJAX Web Forms, it was necessary to maintain a bound (usually also readonly or hidden) column for the key to track the value of the key across requests.

Is that necessary for the grid for MVC Extensions? Or is it handled automatically by the .DataKeys(keys => keys.Add(c => c.MyKeyField).RouteKey("myKeyRouteParameter")) declaration? 
0
Atanas Korchev
Telerik team
answered on 19 Apr 2011, 07:01 AM
Hi Carl,

 All fields added in the DataKeys collection are tracked and sent to your Delete and Updater action methods.

Kind 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
Tags
Grid
Asked by
Carl
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Carl
Top achievements
Rank 1
Share this question
or