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

Action Links in Grid

5 Answers 2635 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 2
John asked on 08 Jan 2018, 07:22 AM

Scenario - Asp.net Core, Razor Pages     

If i have no Controller (using razor pages), is there a way to bind a column to a clientTemplate that contain some sort of Action Link or Navigation link?

I need this so a user can simple click on a link on a row in the grid whicj then does the usual "Edit, Details, Delete"

 

If i was to not have telerik grid and just us a table it would look like this:

 <td>
                <a asp-page="./Edit" asp-route-id="@item.Id">Edit</a> |
                <a asp-page="./Details" asp-route-id="@item.Id">Details</a> |
                <a asp-page="./Delete" asp-route-id="@item.Id">Delete</a>
            </td>
        </tr>
}
    </tbody>
</table>

 

5 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 2
answered on 08 Jan 2018, 07:28 AM

i am almost thee with this but not quite...

 

columns.Bound(p => p.Id).ClientTemplate("<a asp-page='./ Edit' asp-route-id='@item.Id'>Edit</a>");

0
Accepted
Stefan
Telerik team
answered on 10 Jan 2018, 08:37 AM
Hello, John,

The issue occurs because the client template is evaluated on the client where the page does not have access to the RazoPages asp-page attributes.

Currently, the action links can be set in the following format:

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

The other option will be to directly set the href over the anchor element:

.ClientTemplate("<a href=./Edit>Edit</a>");


Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
TESSA
Top achievements
Rank 1
answered on 14 Jun 2020, 07:31 AM

I have seen many queries on Grid custom action links,most of them cover Ajax calls, not many explaining with multiple parameters when using Model binding. 

Here is full page  sample  with BindTo(Model)  

This was done in ,NET Core 3.1  VS2019 MVC project

 

 

@using GridTestActionLink.ViewModels
@using Kendo.Mvc.UI
@model IEnumerable<GridTestActionLink.ViewModels.Users>

@{ ViewData["Title"] = "Index"; }

<h1>Index</h1>

@(Html.Kendo().Grid<Users>()
    .Name("gridUsers")
    .Columns(columns =>
    {
        columns.Bound(c => c.UserId).ClientTemplate("<a href='" + Url.Action("LinkPage", "Home", new {UserId = "#=UserId#", UserName="#=UserName#"}) + "'>#=UserName#</a>");
    columns.Bound(c => c.UserName);
      

    })
    .HtmlAttributes(new { style = "height: 650px;" })
    .Scrollable()
    .Pageable(page =>
    {
        page.Refresh(true)
            .PageSizes(true)
            .ButtonCount(5);
    })
    .ToolBar(t => t.Search())
    .Sortable()
    .BindTo(Model)
    )

0
Petar
Telerik team
answered on 17 Jun 2020, 11:06 AM

Hi Tessa,

Thank you for sharing the example with the community!

Your post will surely help someone who wants to use Action links inside the Grid which data is populated using "BindTo(Model)".

Regards,
Petar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
answered on 15 Jul 2022, 08:31 AM

With the given hints (for MVC), we found that the following seems to be the best and closest implementation to the 'asp-page' syntax:

columns.Bound(column => column.Id).ClientTemplate("<a href='" + @Url.Page("./Details", new { id = "#= Id #" }) + "'>Details</a>");

Petar
Telerik team
commented on 15 Jul 2022, 08:43 AM

Hey, Stefan.

Thank you for sharing the approach that you used!

Tags
Grid
Asked by
John
Top achievements
Rank 2
Answers by
John
Top achievements
Rank 2
Stefan
Telerik team
TESSA
Top achievements
Rank 1
Petar
Telerik team
Stefan
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or