ProfK
ProfK

Reputation: 51063

Problem rendering Telerik MVC Grid in a Razor view

I have the following markup in a 'content' page. Without the Render call, nothing renders, and with the Render call, the grid renders as the first element in the whole page, not inside the 'content' section defined by my view:

@using Telerik.Web.Mvc.UI
@model Outdoor.Mvc.ViewModels.OutdoorSite.SiteList
@{
    Html.Telerik().Grid(Model.ItemList).Name("Site Grid")
        .Columns(columns => 
        {
            columns.Bound(o => o.SiteId);         
            columns.Bound(o => o.Name);
        })
        .Pageable()
        .Sortable()
        .Render();
}

What am I doing wrong?

Upvotes: 3

Views: 2885

Answers (1)

user545835
user545835

Reputation:

This is because of different approach to rendering Razor's views. In order to make it work you have to remove Render() call and build grid in multiline expression block, like this:

@using Telerik.Web.Mvc.UI
@model Outdoor.Mvc.ViewModels.OutdoorSite.SiteList
@(
    Html.Telerik().Grid(Model.ItemList).Name("Site Grid")
        .Columns(columns => 
        {
            columns.Bound(o => o.SiteId);         
            columns.Bound(o => o.Name);
        })
        .Pageable()
        .Sortable()
)

Upvotes: 5

Related Questions