MVCContrib 网格 MVC 3 Razor .RowStart

发布于 2024-11-02 17:00:31 字数 981 浏览 3 评论 0原文

.RowStart 方法的示例遇到问题。

比较 2 种语法: http ://www.jeremyskinner.co.uk/2009/03/01/mvccontrib-grid-part-5-the-action-syntax/

在此

.RowStart(row => string.Format("<tr{0}>", row.IsAlternate ? "style=\"background-color:#CCDDCC\"" : ""))

row.IsAlternate 中抛出错误因为 row 不是 GridRow,它实际上是您的模型(以及行的数据项)。

第二种语法(ActionSyntax):

.RowStart((p,row)  => {     
             if (row.IsAlternate) { %>
                   <tr style="background-color:#CCDDCC">
             <%  }  else  { %>
                 <tr>
             <% }
    }).Render(); %>

似乎没有转换为 Razor

.RowStart((x, row) => string.Format("<tr class='{0}'>", row.IsAlternate ? "grid-row" : "grid-row-alt"))

Passes,但不会发出任何行更改。

有人有这个工作吗?

Having trouble with the examples for the .RowStart method.

Comparing the 2 syntaxes: http://www.jeremyskinner.co.uk/2009/03/01/mvccontrib-grid-part-5-the-action-syntax/

In this

.RowStart(row => string.Format("<tr{0}>", row.IsAlternate ? "style=\"background-color:#CCDDCC\"" : ""))

row.IsAlternate throws an error as row isnt the GridRow, its actually your model (well the row's data item).

The second syntax (ActionSyntax) :

.RowStart((p,row)  => {     
             if (row.IsAlternate) { %>
                   <tr style="background-color:#CCDDCC">
             <%  }  else  { %>
                 <tr>
             <% }
    }).Render(); %>

doesnt seem to translate to Razor

.RowStart((x, row) => string.Format("<tr class='{0}'>", row.IsAlternate ? "grid-row" : "grid-row-alt"))

Passes ok, but doesn't emit any row changes.

Any had this working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔岸观火 2024-11-09 17:00:31

我刚刚注意到 Html.Grid 为您添加了一些约定内容...

以下

Html.Grid(Model.Results).Attributes(@class => "grid")

鉴于class =“grid”的表中的 结果,
偶数行具有 class =“gridrow”,
和类=“gridrow_alternate”的奇数行

I've just noticed some convention stuff that Html.Grid is putting in for you...

Given the Following

Html.Grid(Model.Results).Attributes(@class => "grid")

results in a table with class = "grid",
even rows with a class = "gridrow",
and odd rows with a class = "gridrow_alternate"

度的依靠╰つ 2024-11-09 17:00:31

不确定这是否有帮助,但我最近一直在做的一件事是使用:

.RowAttributes(x => new Dictionary<string, object> { { "class", x.value == myValue ? "highlight" : "" } })

这允许我对属性的 css 值做很多事情。然后为了支持“斑马条纹”,我使用纯CSS(浏览器兼容性可能是一个问题,但它很优雅,只是不会在旧浏览器上呈现)看起来像

tr:nth-child(odd) {
background-color: #eee;}

给你对表格的很好的控制。有关选择器的更多信息 Sitepoint 子选择器

否则,您可以尝试 针对 mvccontib 的 Google 群组 Jeremy 通常很敏锐,会提供帮助。

希望这有帮助。

Not sure if this will help but one thing I've been doing lately is using:

.RowAttributes(x => new Dictionary<string, object> { { "class", x.value == myValue ? "highlight" : "" } })

This allows me to do a lot with css values for the attributes. then for supporting "Zebra striping" I use pure css (browser compatibility could be an issue here, but it's graceful just doesn't render on old browsers) looks something like

tr:nth-child(odd) {
background-color: #eee;}

Gives u great control over the table. More info on the selectors Sitepoint child selectors

Other wise you could try the google groups for mvccontib Jeremy is usually sharp of the mark to help out.

Hope this helped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文