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

Column Template C# to VB Error

4 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Harold
Top achievements
Rank 1
Harold asked on 06 Apr 2011, 11:36 PM
I have an C# view like that and works fine

@model IEnumerable<Customer>

@{ Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Template(@<text><p>Hello World</p> </text>).Title("Accion").Title("Picture");
            columns.Bound(c => c.ContactName).Title("Name");
            columns.Bound(c => c.Phone);
        })
        .Sortable()
        .Scrollable(scrolling => scrolling.Height(250))
        .Pageable()
        .Render();
 }

but then when I wrote it to vb
...
@model IEnumerable(of Customer)
@(Html.Telerik().Grid(Model) _
.Name("Grid") _
.Columns(Function(columns) _
                 columns.Template(@<text><p>Hello World</p> </text>).Title("Action").Title("Picture")
                 columns.Bound(Function(c) c.ContactName).Title("Name")
                 columns.Bound(Function(c) c.Phone)
         End Function) _
.Pageable() _
.Sortable() _
.Filterable() _
.Groupable()

the template function give me an Expression Expected Error


Regards!

4 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 07 Apr 2011, 12:50 PM
Hello Harold,

In VB.NET your Razor template should look like this:

columns.Template(Sub(o) @<text>Some template goes here for ID = @o.ID </text> End Sub)

For your convenience I am attaching sample mvc application.
You can find more details on the forum threads bellow:
http://www.telerik.com/community/forums/aspnet-mvc/grid/mvc-grid-using-vb-net.aspx
http://www.telerik.com/community/forums/aspnet-mvc/grid/vb-net.aspx

Greetings,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Harold
Top achievements
Rank 1
answered on 07 Apr 2011, 05:04 PM

Thank you very much I appreciate your fast and complete response with an example included


0
Alex
Top achievements
Rank 2
answered on 10 Nov 2011, 12:48 AM
Ok this is an older thread so sorry for the thread necromancy but it's related to the original question and the example provided by Nikolay Rusev.

I am trying to do something simular and the example provided by Nikolay works great while mine gives me a "weird" result. If I convert mine to what is in the example it works but I believe both should give the same results.

Any insight would be great.

Here's my original that gives me the weird result:

@(Html.Telerik().Grid(Model) _
       .Name("grdDemo") _
       .Columns(Sub(Columns)
                        Columns.Bound(Function(o) o.DUPDE_PLANNING_HEADER_ID).Visible(False)
                        Columns.Bound(Function(o) o.DUPDE_SBMS_DEMO_ID).Visible(False)
                        Columns.Bound(Function(o) o.CustomName).Title("Demographic")
                        Columns.Template(Sub(o)@<text>Some template goes here for ID = @o.DUPDE_POPULATION </text> End Sub).Title("Template Column")
                        Columns.Bound(Function(o) o.DUPDE_POPULATION).Title("Population")
                End Sub) 
      )


But if I use the gridBuilder method of the example it works as expected.

@code
    Dim gridBuild As Telerik.Web.Mvc.UI.Fluent.GridBuilder(Of DUCS.UDV_PLANNING_DEMO) = Html.Telerik().Grid(Model).Name("Grid")
      
    gridBuild.Columns(Function(columns As Telerik.Web.Mvc.UI.Fluent.GridColumnFactory(Of DUCS.UDV_PLANNING_DEMO)) columns.Bound(Function(o) o.DUPDE_PLANNING_HEADER_ID))
    gridBuild.Columns(Function(columns As Telerik.Web.Mvc.UI.Fluent.GridColumnFactory(Of DUCS.UDV_PLANNING_DEMO)) columns.Template(Sub(o)@<text>Some template goes here for ID = @o.DUPDE_POPULATION </text> End Sub).Title("Template Column"))
    gridBuild.Render()
End Code

As always thanks to everyone for taking the time.
0
Petur Subev
Telerik team
answered on 11 Nov 2011, 04:36 PM
Hello Alex,

This is needed because in VB.NET, Razor does not support inline templates (like C# does). To make it work in VB.NET you should use the .Render() method when defining the Grid.


All the best,
Pesho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Harold
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Harold
Top achievements
Rank 1
Alex
Top achievements
Rank 2
Petur Subev
Telerik team
Share this question
or