Hello,
I would like to know if i can add an ActionLink in a column in my DetailTemplate:
The only way I've found is by using a Template , for exemple :
.Columns(col => {
col.Bound(p => p.Etat).Template(@<text>@Html.ActionLink("Edit", "Edit")</text>);
})
But like i'm already in a DetailTemplate , i get an error when i try to do this :
.DetailTemplate(
@<text>
@(Html.Kendo().Grid<Affaire>()
.Name("Affaires_" + item.Id)
.Columns(col => {
col.Bound(p => p.Name).Template(@<text>@Html.ActionLink("Edit", "Edit")
</text>)
Is there another way to make this link work ?
Thanks
5 Answers, 1 is accepted
You can create action Links inside the DetailTemplate using ClientTemplate() method and omitting the <text> declarations and @ signs.
.DetailTemplate(@<
text
>
@(Html.Kendo().Grid<
KendoMVC.Models.OrderViewModel
>()
.Name("Affaires_" + @item.Id)
.Columns(col =>
{
col.Template(x => x).ClientTemplate(Html.ActionLink("Edit", "Home", new { id = item.Id }).ToHtmlString());
})
)
</
text
>)
The template() method was designed for the first level block, it will not have any effect in a nested template.
I hope this will prove helpful.
Kind Regards,
Attila Antal
Progress Telerik
Thanks you , it worked well.
I have another question however :
In this situation , if I have different class for the parent and the child , how could I use the variables of my child ? (for exemple, in the action link attributes )
I've tried new { id = item.Id } but item is the parent , so i tried "#=Id#" , "//#=Id//#" , "#:Id#" and so on but i can't find the one who works…
Thank you
The first method you've tried is the correct one ( #= FieldName # ). If you open the developer tools of the browser and refresh the page, do you receive error messages?
You may also double check the datasource to ensure that the field "Id" exists.
Example of evaluating data:
.DetailTemplate(@<
text
>
@(Html.Kendo().Grid<
KendoMVC.Models.OrderViewModel
>()
.Name("Affaires_" + @item.OrderID)
.Columns(col =>
{
col.Bound(p => p.Freight);
col.Template(x => x).ClientTemplate(Html.ActionLink("#=Shipname#", "ShipName", "#= OrderID #").ToHtmlString());
})
.DataSource(dataSource => dataSource)
)
</
text
>)
I look foward to hearing from you.
Kind regards,
Attila Antal
Progress Telerik
Hi Attila,
Your example works I was just using Bound and not Template.
Thank you for your reply and your time.
I am glad the issue has ben resolved!
Kind regards,
Attila Antal
Progress Telerik