开发者

Telerik Grid ServerTemplate problem

开发者 https://www.devze.com 2023-04-05 03:24 出处:网络
I\'m trying to set up a Master/Detail grid using the Grid control from Telerik\'s Extensions for ASP.NET MVC.My problem is setting up the server template.

I'm trying to set up a Master/Detail grid using the Grid control from Telerik's Extensions for ASP.NET MVC. My problem is setting up the server template.

The demo I'm following is the first one on this page, except I'm using Razor View Engine.

I have the grid displaying fine. The problem is that I cannot write any sort of a server template that doesn't throw a compiler error - aside from leaving it blank!

@(Html.Telerik().Grid(Model)
            .Name("Grid")
            .Columns(columns =>
            {
                columns.Bound(o => o.Date).Format("{0:MM/dd/yyyy}").Width(100);
                columns.Bound(o => o.Title).Template(@<text> <a href="/Media/@item.Slug">@item.Title</a></text>).Sortable(false);
                columns.Bound(o => o.Publication).Width(120).Sortable(false);
            })
            .DetailView(detailView => detailView.Template(e =>
            {
                //Anything other than this comment will throw a compiler error
            }))
            .RowAction(row =>
            {
                // Expand initially the detail view of the first row
                if (row.Index == 0)
                {
                    row.DetailRow.Expanded = true;
                }
            })
            .Sortable()
            .Scrollable(scrolling => scrolling.Height(494)).Footer(false)
            .ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
        )

See that comment "anything other than this comment..."? When I replace that with something like @<text> hello</text>, I get a compilation error:

CS1002: ; expected

That doesn't seem to make sense, but I humour myself and put a semicolon in like such @<text> hello</text>;. That gives me this error:

CS0201: Only assignm开发者_开发问答ent, call, increment, decrement, and new object expressions can be used as a statement

When I replace that with a portion of the template I really want, namely @<text><b>Slug</b>: @item.Slug</text>, I get the same errors; CS1002 with no semicolon, and CS0201 with a semicolon.

What am I missing here?


There are two ways you can approach this. If you just want to display some simple text and not really integrate any other components it would be the easiest to modify the code you have above to just do this:

.DetailView(detailView => detailView.Template(@<text>test</text>))

As you can see I removed the whole e => { ... } part and just put in @<text></text>.

However, if you want to look into getting more components in your detail view I think it would be better to look at the demo found here. Although the description mentions some WebForms code you don't need to worry, the rest is all in Razor :) It also explains things you have to keep in mind. One of the most important ones is that any components within the DetailTemplate will have to use { ... } as opposed to ( ... ) this is because you want to specifically call .Render(); (using the ( ... ) implicitly calls .Render but at the wrong point for these scenarios) at the end of those components' declaration to make sure they are all rendered correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消