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

Adding links to fields in an MVC Grid

5 Answers 224 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.
John
Top achievements
Rank 1
John asked on 08 Oct 2010, 04:36 AM
Hi, i have a possibly odd request. First off, i just started using this software today and it is amazing! If the devs see this, great job! Such a powerful tool. Anyways, my question:
I have a grid, and instead of using the built in edit/delete commands, i want to route to a controller action so i can do those commands in my own way, as well as some special commands that specific to my project. So my question is, can i put links into column fields?
I hope this makes sense, i normally have trouble conveying my problems.

5 Answers, 1 is accepted

Sort by
0
Jigar
Top achievements
Rank 1
answered on 08 Oct 2010, 05:45 AM
Hi John,

You may have a look at this

I hope this may help.

Regards,

Jigar.
0
John
Top achievements
Rank 1
answered on 08 Oct 2010, 05:22 PM
I think the link you gave me pushed me in the right direction, but im kind of stuck still.

columns.Bound(o => o.LocationId).Format(Html.ActionLink("Edit", "Edit", "Location",
                        new { id = "{0}", height = 550, width = 900, modal = "true" },
                        new { @class = "t-link action-edit thickbox" }).ToString()).Title(" ").Encoded(false).Width(25).Sortable(false).Filterable(false)

The problem that Uma was having with this was that the html.actionlink was displaying as text. Which is the same problem i am having. Only he didnt post his solution.
0
Accepted
Binu
Top achievements
Rank 1
answered on 08 Oct 2010, 05:29 PM
Use Ajax binding instead of server side binding, refer to sample project,

for edit link, define your column model like this
.Columns(columns =>
             {
             columns.Bound(s => s.Name);
             columns.Bound(s => s.Status);
             columns.Template(s => Html.ActionLink("Edit", "EditView", new {s.Id}))
             .ClientTemplate("<a href=\"" + Url.Action("EditView", "MyController") + "/<#= Id#>\">Edit</a>")
             .Title("Edit");
             }
     )

.Template is run on server, so you can create an action link, .ClientTemplate  takes care of Ajax paging.

Hope this helps
0
John
Top achievements
Rank 1
answered on 08 Oct 2010, 05:54 PM
That worked perfectly. Thanks!
0
Jeremy
Top achievements
Rank 1
answered on 01 Mar 2013, 06:03 PM
Here is a take on Binu's excellent answer that worked for me in Telerik MVC version 2012.1.214.

            columns.Bound(o => o.CustId).Title("CustId").ReadOnly(true).Width(75)
                .ClientTemplate("<a href=\"" + Url.Action("MyAction", "MyController") + "?id=<#=CustId#>\"><#=CustId#></a>");
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Jigar
Top achievements
Rank 1
John
Top achievements
Rank 1
Binu
Top achievements
Rank 1
Jeremy
Top achievements
Rank 1
Share this question
or