@Html.Telerik.Grid(Model). Name("matches"). Columns(Sub(cols) With cols .Bound(Function(o) o.Player1) .Template(Sub(o) @<text> <img alt="@o.LocalTeamName" src="@Url.Content("~/Content/TeamLogos/" & o.LocalTeamName & ".png")" /> </text> End Sub).Title("Logo") End With End Sub)The end result is that the images are rendered *before* the table and the column that's supposed to render those images is empty. That column has a correct heading, but the content for template columns seems to run before the actual rendering of the grid.
This looks just like the sample in the demo page but there must be something off. What am I doing wrong?
Thanks
Andrés
7 Answers, 1 is accepted
This is not the proper way to declare a razor template. Please check the razor template example for a working demo (check the view tab of the code viewer). Here is the relevant code:
@{ Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Template(
@<text>
<img
alt="@item.CustomerID "
src="@Url.Content("~/Content/Grid/Customers/" + item.CustomerID + ".jpg") "
/>
</text>
).Title("Picture");
Regards,
Atanas Korchev
the Telerik team
Thanks for your reply. But I'm not using C#, It's VB.
Unfortunately, your demo site doesn't have any visual basic samples, but so far I managed to make everything work in vb except for this.
Cheers,
Andrés
I believe the VB code for setting the template in Razor is the same. Did you try it?
All the best,Atanas Korchev
the Telerik team
Yes I tried it.
In vb, you must type the "sub(item)" part because otherwise you get an "expression expected" compiler error.
Thanks,
Andrés
In that case you can try rendering the grid inside a razor block - call its Render method:
@Code Html.Telerik().Grid().Render()End CodeKind regards,
Atanas Korchev
the Telerik team
Should I file a bug or something?
Thanks
This seems to be a limitation of the Razor support for VB.NET. I tried the following with the built-in WebGrid helper:
@Code
ViewData("Title") = "Home Page"
Dim grid As New WebGrid(New String() {"One", "Two"})
End Code
@grid.GetHtml(alternatingRowStyle:="alt",columns:=grid.Columns(
grid.Column("Foo",format:= Function(item)@<text>$@item</text> End Function)))
The result was exactly the same. I also found the following pages discussing the same issue:
http://stackoverflow.com/questions/5136270/razor-inline-template-item-keyword-in-vb
http://forums.asp.net/t/1657902.aspx/2/10?Razor+Inline+Template+Item+Keyword+in+VB
Regards,
Atanas Korchev
the Telerik team