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
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://es.infragistics.com/support
Hello Maya,
Thanks for the example. However I am using C# code to set the template of a column on the GridModel and not doing it in the cshtml file. Do you have example code for that aswell ?
var model = new GridModel();model.Columns.Add(new GridColumn("Name", "Name", "string", "220px") { Template = """});