0
votes

I am new to Kendo and are trying to add a custom command to a grid. I have been going over example pages, StackOverflow, and Telerik's site and found multiple examples that has the following:

columns.Command(command =>
{ 
     command.Custom("Details").Text("Show Details").Action("Details", "Billing"); 
});

When I try to use this, I get the following error:

'GridCustomActionCommandBuilder' does not contain a definition for 'Action' and the best extension method overload 'UrlHelperExtensions.Action(IUrlHelper, string, object)' requires a receiver of type 'IUrlHelper'

I then tried this example from telerik:

columns.Template(@<text>@Html.ActionLink("Edit", "Home", new { id = item.ProductID })</text>);

But get this error:

Cannot convert lambda expression to type 'string' because it is not a delegate type

Just to confirm what is causing the error, then took out the ActionLink and used only this:

columns.Template(@<text>
    <div>help me!!</div>
</text>);

and got the same error:

The total code snippet looks like this:

@(Html.Kendo().Grid<OrganisationEmployeesViewModel>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.EmployeeID).Visible(false);
        columns.Template(@<text>
                            <div>help me!!</div>
                        </text>);
    })

    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .HtmlAttributes(new { style = "height:550px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Read(read => read.Action("Employees_Read",  "Organisations"))
     )
     .Deferred()
)

I am using existing samples but don't know what is wrong.

1
Have you included all the necessary kendo script references in your view (possibly layout view)? - counterflux
@counterflux As stated above, I am new to kendo. I have references to kendo.aspnetmvc.min.js and kendo.all.min.js on my _Layout.cshtml file. Are there more referenced I need to add? How do I add them? - MerlinNZ
I hava a bundle with: ~/Content/kendo/2016.1.226/kendo.common.min.css ~/Content/kendo/2016.1.226/kendo.mobile.all.min.css ~/Content/kendo/2016.1.226/kendo.dataviz.min.css ~/Content/kendo/2016.1.226/kendo.flat.min.css ~/Content/kendo/2016.1.226/kendo.dataviz.flat.min.css ~/Scripts/kendo/2016.1.226/jquery.min.js ~/Scripts/kendo/2016.1.226/jszip.min.js ~/Scripts/kendo/2016.1.226/kendo.all.min.js That I use for my applications. Your code doesn't seem to give me errors. also don't forget to add JQUERY in nuget package manager. - counterflux
The Action is called in Razor, which is called from C# (Server-side DLL) and thus could not be related to Javascript not loaded. I have tried this not the less and still have the same error. command.Custom("Details").Text("Show Details").**Action**("Details", "Billing"); - MerlinNZ
Instead of .Action("Details", "Billing") have you tried .Click("Details", "Billing")? - ShawnOrr

1 Answers

0
votes

I found a way for this to work:

        columns.Template("<a href='" +
            Url.Action("ControllerAction", "Controller") +
            "?Parameter=#= RecID #'" +
        ">DisplayText</a>");

This can also be applied to a bound column like this:

        columns.Bound(p => p.Name).ClientTemplate("<a href = '" +
            Url.Action("Details", "Employees") +
            "/#= EmployeeID #'" +
        ">#=Name#</a>");

And should you want to have a Custom Toolbar Action on the Kendo Grid: I am using the standard bootstrap classes to apply defaults:

    .ToolBar(t => t.ClientTemplate("<a class='k-button k-button-icontext k-grid-add' href='" +
            Url.Action("OrganisationCreate", "Employees", new { OrganisationId = Model.OrganisationID }) +
            "'><span class='k-icon k-add'></span>Add new Employee</a>") )