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

Custom command routevalue

3 Answers 718 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bart
Top achievements
Rank 1
Bart asked on 22 May 2014, 08:21 AM
Hi,

I'm trying to add a custom command to a grid. The goal is to show me the details of a record, so I need to pass the Id to my controller.
In the help I've found the following syntax:
.Action(actionName, controllerName, routeValues);

How do I add a my record Id to "routeValues"? I can't find an example.

I would like something like this:
....
columns.Bound(c => c.TopChar1);
columns.Command(command => command.Custom("Details").Action("Details", "Pres", new { Id = ????? }));
....

So far, I've only found a workaround using a javascript combined with Custom("Details").Click("function").

Thx

3 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 26 May 2014, 07:52 AM
Hello Bart,

You can add the needed fields to the route values with the DataRouteValues method:
columns.Command(command => command.Custom("Details").Action("Details", "Pres").DataRouteValues(routeValues =>
{
    routeValues.Add(o => o.Field1);
    routeValues.Add(o => o.Field2);
    ...
but note that setting an action and controller for a custom command is supported only in server binding mode. If you are using Ajax binding then you should either use the click handler or use a template column with a link as demonstrated here.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Bart
Top achievements
Rank 1
answered on 27 May 2014, 07:45 AM
Thanks for your help.
I already tried that however. I can make it work that way, but the problem I have is that this way you generate a parameter instead of just a clean url. It's not the biggest problem in the world, but it means I have to adjust my server code.
What I want is this:
     columns.Command(command => command.Custom("Details").Action("Details", "Pres", new { Id = "24" }));
     -> http://localhost:53698/Pres/Details/24
Your code gives this result:
     -> http://localhost:53698/Pres/Details?InvNrPres=24

The .Action(actionName, controllerName, routeValues) gives me the URL-structure I want, I just don't know how to implement it.


0
Bart
Top achievements
Rank 1
answered on 27 May 2014, 02:32 PM
Nevermind,

It was my fault: changing the parameter-name "invpresnr" to the default "id" solved my problem.

Thx
Tags
Grid
Asked by
Bart
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Bart
Top achievements
Rank 1
Share this question
or