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

ClientTemplate and HTML.ActionLink

4 Answers 1043 Views
Grid
This is a migrated thread and some comments may be shown as answers.
markg
Top achievements
Rank 1
markg asked on 27 Jul 2012, 12:47 PM
Hi,

I'm trying to use HTML.ActionLink in ClientTemplate, and I fail to pass arguments into ActionLink.

new { path = "<#= DataPath #>" } - doesn't work.
Any ideas how to "inject" the value into route values?
@(Html.Kendo().Grid<Admin.Models.FileToken>().Name( "mygrid" )
                .Columns( columns => {
                    columns.Bound( f => f.Title ).Width( "70%" );
                    columns.Bound( f => f.Size ).Width( "20%" ).Format( "{0:N2}MB" );
                    columns.Bound( f => f.DataPath ).Width( "10%" )
                    // Doesn't work
                    .ClientTemplate(Html.ActionLink( "Run", "ProcessFile", new { path = "<#= DataPath #>" } ).ToHtmlString() );
                } )
                .DataSource( source => source
                    .Ajax()
                    .Model( model => model.Id( key => key.DataPath ) )
                    .Read( reader => reader.Action( "GetDataFileTokens", "Dashboard" ) )
                )
        )

4 Answers, 1 is accepted

Sort by
0
Damian
Top achievements
Rank 1
answered on 31 Jul 2012, 03:46 PM
I actually came across your question while looking for an answer to this exact issue. The problem was that the RouteValues object was escaping the string before it could be injected by the Grid. So after some thought I came up with this.

columns.Bound(m => m.Name).ClientTemplate(Html.ActionLink("#=Name#", "Edit", new { Id = "id" }).ToHtmlString().Replace("id", "#=Id#"));

The Replace function doesn't escape the string, and it all works nicely. There may be a better way to do it, but that's just what I came up with after about 10 minutes of head scratching.
0
Ragan
Top achievements
Rank 1
answered on 09 Aug 2012, 09:37 PM
Damian !

You saved my life, I was able to fix my problem and now I get my actionLink they way I wanted.

Since my grid is using Ajax, my final code looks like this:

columns.Bound(m => m.ClientPayeeCodeId)
                    .Template(cp =>
                        Html.ActionLink("Details""Details"new { id = cp.ClientPayeeCodeId })
                    )
                    .ClientTemplate(Html.ActionLink("Details""Details"new { Id = "id" }).ToHtmlString().Replace("id""#=ClientPayeeCodeId#"));
0
Venkata
Top achievements
Rank 1
answered on 01 Feb 2019, 11:48 AM

I am using below code to make an link Grid column to call an action , I couldn't able to see column  data as link 

columns.Bound(m => m.Project).Template(cp => Html.ActionLink("#=ProjectTitle#", "AddProject", "Header", new { Id = Model.Id, Id1 = cp.Id1 }))
                    .ClientTemplate(Html.ActionLink("AddProject", "Header", new { Id= "Id", Id1= "Id1" }).ToHtmlString().Replace("Id","#=Id#").Replace("Id1", "#=Id1#"));

0
Alex Hajigeorgieva
Telerik team
answered on 06 Feb 2019, 08:17 AM
Hello, Damian,

Thank you for sharing this approach with the Kendo UI community.

This is actually one of the frequently asked questions at:

https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-use-action-links

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
markg
Top achievements
Rank 1
Answers by
Damian
Top achievements
Rank 1
Ragan
Top achievements
Rank 1
Venkata
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or