Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2732
Column Template ActionLink
posted

Hello,

I'm trying to have a column with a template to display a link. 

The following template works: "<a href='/DevOps/SoftwareInformation/Filter/${Name}'>${Name}</a>"
However, I would like to create a Html.ActionLink to directly link to the controller & action. 

In my cshtml file this is how I would do it:
@Html.ActionLink(linkText:"Test Filter", actionName:"Filter", controllerName:"SoftwareInformation", routeValues:new { id="Test"}, htmlAttributes:null)

However, I don't manage to translate this to a column template. Everything I try just gets translated to pure text.

This is the code I use to define the column:

model.Columns.Add(new GridColumn("Name", "Name", "string", "220px") {
    Template = @"Html.ActionLink(linkText:""${Name} Filter"", actionName:""Filter"", controllerName:""SoftwareInformation"", routeValues:new { id=""${Name}""}, htmlAttributes:null)"});

Any advice ?

Kind regards,

Michael

Parents
  • 29417
    Offline posted

    Hello Michael,

     

    Thank you for posting in our forum.

     

    The Template for the column you set needs to be a string. What Html.ActionLink ultimately renders on a page is html so once you define the action link you can call its ToHtmlString() method and pass the result to the Template for the column. For example:

    col.For(x => x.Name).Template(@Html.ActionLink(linkText: "${Name}",actionName: "Index",controllerName:"Home").ToHtmlString());

     

    Let me know if you have any questions.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer II

    Infragistics, Inc.

    http://ko.infragistics.com/support

     

Reply Children