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

GridBoundColumnBuilder<MyModel>' does not contain a definition for 'Template'

3 Answers 1725 Views
Grid
This is a migrated thread and some comments may be shown as answers.
T
Top achievements
Rank 1
Iron
T asked on 05 Feb 2021, 05:26 PM

I have a working server-bound grid. I'm trying to add a server-bound template column based on the following snippet from here.

 

columns.Bound(p => p.ProductName).Template(@<text>
    @if(@item.ProductName != null){
         @item.ProductName
    } else {
        "No data"
    }
    </text>
);

 

 

The ".Template" method generates the error:

Error CS1061 'GridBoundColumnBuilder<MyModel>' does not contain a definition for 'Template' and no accessible extension method 'Template' accepting a first argument of type 'GridBoundColumnBuilder<MyModel>' could be found (are you missing a using directive or an assembly reference?)

These lines are in my _ViewImports.cshtml:

@addTagHelper *, Kendo.Mvc
@using Kendo.Mvc.UI

Using Telerik.UI.for.AspNet.Core 2020.3.915

https://demos.telerik.com/aspnet-mvc/grid/serverrowtemplate

I have not yet found a solution after looking at many links. Am I really missing a using?

(And for the record, the New Thread editor for these forums is shameful. The standard Windows undo/redo/selection do not work in Chrome and poor/lack of formatting options significantly limit what I'm trying to convey.)

Mia
Top achievements
Rank 1
commented on 12 Dec 2022, 03:47 PM

Hi,

 

This could be unrelated, but when I was getting this error I was not properly closing out one of my other blocks of code.

 

For example, I was attempting to add an .editable popup but did add the ending ). This caused columns to be under an incorrect parent property it was not associated with.

This likely is not your problem, but writing just in case.

Anton Mironov
Telerik team
commented on 14 Dec 2022, 10:19 AM

Hi Mia,

Thank you for sharing this with the community.

If any further assistance is needed - do not hesitate to contact me and the team.


Kind Regards,
Anton Mironov

3 Answers, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 09 Feb 2021, 12:58 PM

Hello,

Thank you for the code snippet and details provided.

In this case, I would recommend double-checking the ~Views/web.config file for the following row:

<namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="Kendo.Mvc.UI" />
</namespaces>
If the config file is ok, follow the steps from the following article:

Let me know if the steps above resolve the issue. If the issue persists - the fastest route to getting you up and running is if you could provide a runnable, isolated, sample project. Examining this project will let us replicate the issue locally and further troubleshoot it.

Furthermore, I created a sample MVC project(attached) that includes all the needed dependencies. Use it as a template, or as you decide for the needs of your application.

Looking forward to hearing back from you.

Kind Regards,
Anton Mironov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
T
Top achievements
Rank 1
Iron
answered on 09 Feb 2021, 02:53 PM

The grid is completely working without the template column, and the web app is on .Net Core 3.1 so does not have a web.config. From the csproj file, and this is the same version listed in the Solution Explorer dependencies:

 

<PackageReference Include="Telerik.UI.for.AspNet.Core" Version="2020.3.915" />

 

Unfortunately I do not have time to create a mock Ultimately, we'd just like more documentation: a snippet of the Template extension method. This was as far as we got:

public static class TelerikExtensions
{
     public static GridBoundColumnBuilder<T> Template<T>(this GridBoundColumnBuilder<T> item, Func<T, HelperResult> template) where T : class
{
 return item;
}

}

 

We could not connect the dots between this and the blog post referenced in the existing Telerik documentation and have since moved to a client-side work around.

0
Anton Mironov
Telerik team
answered on 11 Feb 2021, 01:15 PM

Hello,

Thank you for the additional details provided.

In this case, I would recommend using one of the following approaches:

I hope this information helps. Let me know if the first approach is achieving the desired behavior.

 

Best Regards,
Anton Mironov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Sumi
Top achievements
Rank 1
commented on 03 Dec 2021, 10:14 PM

@T I added the link with following template:

   @(Html.Kendo().Grid(Model.MyModel)
                .Name("users-grid")
                .Columns(col => {
                             col.Bound(f => f.modelField).Width(100).ClientTemplate("<a href='" + Url.Action("Action", "Controller", new { id = "\\#= id \\#" }) + "'>\\#= modelField \\#</a>");
                    
                })
                .ToClientTemplate()
            )
Anton Mironov
Telerik team
commented on 07 Dec 2021, 12:47 PM

Hi Sumi,

Thank you for sharing your approach with the community.

If further assistance is needed, do not hesitate to contact me and the team.

Kind Regards,
Anton Mironov
Tags
Grid
Asked by
T
Top achievements
Rank 1
Iron
Answers by
Anton Mironov
Telerik team
T
Top achievements
Rank 1
Iron
Share this question
or