Problem rendering Telerik MVC Grid in a Razor view

我的未来我决定 提交于 2019-12-06 08:25:25

问题


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?


回答1:


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()
)


来源:https://stackoverflow.com/questions/4458753/problem-rendering-telerik-mvc-grid-in-a-razor-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!