I have an NVC4 kendo grid in which I want to place a button which, when pressed, will call an ActionLink with an ID taken from a column in the current row. In my case this will jump to a new page to display a map of the location by calling the MVC action method via the URL ~/Controller/ShowMap?Id=123 (if the Id was 123)
I have found columns.Command method and have written the following code
@(Html.Kendo().Grid(Model)
.Name("SchemeResults")
.Columns(columns =>
{
columns.Bound(p => p.Id).Hidden();
columns.Bound(p => p.SchemeName);
columns.Command(command => command.Custom( "Map") .Click("GotoMap"));
})
.Pageable()
)
Please could you advise me on the best way to implement this feature.
10 Answers, 1 is accepted

@(Html.Kendo().Grid(Model)
.Name("SchemeResults")
.Columns(columns =>
{
columns.Bound(p => p.Id).Hidden();
columns.Bound(p => p.SchemeName);
columns.Template(c => @Html.ActionLink("Map", "TestMap", new { id = c.Id, }));
})
.Pageable()
)

I repeat what Craig said to save you going there. Craig says:
Just thought I'd add to this thread with a solution I found.
columns.Bound(o => o.Name).ClientTemplate(@Html.ActionLink("#=Name#", "Edit", new { ID = "#=ID#" }).ToHtmlString());
Using the ActionLink helper (rather than hard coding the tags) means we can tap into the routing system, making maintenance a lot easier later on.
Thanks Craig. That solved my problem nicely.


To add onto what Jon Smith's answer, you can still use html tags as opposed to the ActionLink helper. This is useful if you want to have custom classes or add icons etc.
columns.Bound(p => p.Id).ClientTemplate("<
a
href
=
'" + @Url.Action("Index", "Invoice", new { id = "#=Id#" }) + "'
class
=
'btn btn-primary'
><
i
class
=
'fa fa-eye'
></
i
> View</
a
>" ).Width(90);
Note: You can also define your own helpers to use in these scenarios, but this would be the 'quick and dirty' way of customizing the button.

http://localhost:51422/Contract/TransactionSummary?Length=4
Instead of:
https://info.verdantcc.com/Home/TransactionSummary?contractOid=273
What am I missing?
================================================
@(Html.Kendo().Grid<Shared_ViewModels.Contract.ContractListItemVM>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.ContractOid).Hidden();
columns.Bound(c => c.ContractIDCoalesced).Width(40).Title("Contract ID")
.ClientTemplate(@Html.ActionLink("#=ContractIDCoalesced#", "TransactionSummary", "Home", new { contractOid = "#=ContractOid#" }).ToHtmlString());
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("ContractList3_GetData", "Contract"))
)
.DataSource(dataSource => dataSource.Ajax()
.PageSize(20)
.ServerOperation(false)
)
)

If i remove the controller name it works as expected except it sends it to the wrong controller. How do I get this statement to work with the controller name parameter?
columns.Bound(c => c.ContractIDCoalesced).Width(40).Title("Contract ID")
//.ClientTemplate(@Html.ActionLink("#=ContractIDCoalesced#", "TransactionSummary", "Home", new { contractOid = "#=ContractOid#" }).ToHtmlString()); <=== This doesn't work
.ClientTemplate(@Html.ActionLink("#=ContractIDCoalesced#", "TransactionSummary", new { contractOid = "#=ContractOid#" }).ToHtmlString()); <===This works but doesn't send it to the correct controller

It looks like the controller name parameter is causing the issue. I need to include the controller name "Home". If I include a controller name, then the query string says, length=4. If I remove the controller parameter, then the query string is correct except that it goes to the wrong controller.
Is there a fix for this behavior?
Try passing null as the last argument of Html.ActionLink and the issue should be resolved.
columns.Bound(c => c.ContractIDCoalesced).Width(40).Title(
"Contract ID"
)
.ClientTemplate(@Html.ActionLink(
"#=ContractIDCoalesced#"
,
"TransactionSummary"
,
"Home"
,
new
{ contractOid =
"#=ContractOid#"
},
null
).ToHtmlString());
For reference check the stackoverflow article below:
Regards,
Viktor Tachev
Progress Telerik


Found a solution:
columns.Bound(p => p.ContractOid).Width(40).Title("Contract ID")
.ClientTemplate(
"<a href='" +
Url.Action("TransactionSummary", "Home") +
"?contractOid=#= ContractOid #'" +
">#= ContractIDCoalesced #</a>"
);