Telerik Grid Server模板问题
我正在尝试使用 Telerik 的 ASP.NET MVC 扩展中的网格控件来设置主/详细信息网格。我的问题是设置服务器模板。
我正在关注的演示是 此页面,但我使用的是 Razor View Engine。
我的网格显示良好。问题是我无法编写任何类型的不会引发编译器错误的服务器模板 - 除了将其留空之外!
@(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"))
)
看到那个评论“除了这个评论之外还有什么……”吗?当我用 @
,我收到编译错误:
CS1002: ;预期
这似乎没有意义,但我幽默自己并在其中添加了分号,例如 @
。这给了我这个错误:
CS0201:只有赋值、调用、递增、递减和新对象表达式可以用作语句
当我将其替换为我真正想要的模板的一部分时,即 @
,我得到了同样的错误; CS1002 没有分号,CS0201 有分号。
我在这里缺少什么?
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 assignment, 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种方法可以解决这个问题。如果您只想显示一些简单的文本而不真正集成任何其他组件,那么修改上面的代码来执行此操作是最简单的:
如您所见,我删除了整个 e =>; { ... } 部分,只需放入
@
即可。但是,如果您想在详细视图中获取更多组件,我认为最好查看 演示在这里找到。尽管描述中提到了一些您无需担心的 WebForms 代码,但其余的都在 Razor 中:) 它还解释了您必须记住的事情。最重要的问题之一是 DetailTemplate 中的任何组件都必须使用 { ... } 而不是 ( ... ),这是因为您想要专门调用 .Render(); (在这些组件声明的末尾使用 ( ... ) 隐式调用 .Render 但在这些场景的错误点)以确保它们全部正确呈现。
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:
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.