asp.net-mvc-3html-helpertelerik-gridtelerik-mvc

Implement an @html.myTelerikGrid extension


I'm trying to do an HTML Extension to render my telerik grid with the common settings

If I declare this code into a view everything its fine.

@imports Telerik.Web.Mvc

@imports Telerik.Web.Mvc.UI
 

@Code

Dim gridBuilder As Telerik.Web.Mvc.UI.Fluent.GridBuilder(Of TModel) =

Html.Telerik().Grid(Of TModel)().Name("myList")

@End Code

But I move it into a class library project to implement an HTML extension

Imports System.Web.Mvc

Imports Telerik.Web.Mvc

Imports Telerik.Web.Mvc.UI


Namespace Helpers

    Module HelperList

        <System.Runtime.CompilerServices.Extension()> _

        Public Sub myTelerikList(Of TModel As Class)(helper As HtmlHelper)

            Dim gridBuilder As Telerik.Web.Mvc.UI.Fluent.GridBuilder(Of TModel) = Html.Telerik().Grid(Of TModel)().Name("myList")


…

…

        End Sub

I'm having an error like that

'Html' is ambiguous, imported from the namespaces or types 'Telerik.Web.Mvc.UI, System.Web.Mvc'.


Solution

  • Try using the helper instance which you are extending:

    <System.Runtime.CompilerServices.Extension()> _
    Public Sub myTelerikList(Of TModel As Class)(helper As HtmlHelper)
        Dim gridBuilder As Telerik.Web.Mvc.UI.Fluent.GridBuilder(Of TModel) = helper.Telerik().Grid(Of TModel)().Name("myList")
        ...
    End Sub