如何使用 ASP.Net MVC3 隐藏 Web 网格中隐藏字段的列?
我如何隐藏应该从视图中隐藏的列。我通过隐藏对象来处理此问题,但该列在 UI 中仍然显示为瘦列,行中没有任何内容。有什么办法可以防止物品被绘制吗?
grid.Column(null, null, format: @<input type="hidden" name="RevisionId" value="@item.LatestRevisionId"/>)
谢谢。
How would I hide a column that should be hidden from view. I handled this by hiding the object, but the column still shows in the UI as a skinny column with nothing in the rows. Is there way to prevent the item from being drawn?
grid.Column(null, null, format: @<input type="hidden" name="RevisionId" value="@item.LatestRevisionId"/>)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WebGrid 帮助程序允许您使用
style
属性将 CSS 类应用到各个列。不幸的是,虽然这将允许您隐藏 tbody 部分内的列,但您无法将不同的样式应用于列标题。您可以将相同的样式应用于所有列,这使得它毫无用处。因此,一种可能性是使用 CSS:这假设您想要隐藏第一列并且客户端浏览器支持
:first-child
伪选择器,旧版浏览器可能不会出现这种情况。因此,如果您需要支持旧版浏览器,您可以使用 jQuery 将隐藏样式应用于标题和第一列的行,或者直接隐藏它们:
如果您想要更多控制,我建议您查看 < a href="http://mvccontrib.codeplex.com/wikipage?title=Grid" rel="noreferrer">MvcContrib 网格 或 Telerik 网格。
The WebGrid helper allows you to apply a CSS class to individual columns using the
style
property. Unfortunately while this will allow you to hide the column inside thetbody
section you cannot apply different styles to column headers. You can apply the same style to all columns which makes it pretty useless. So one possibility is to use CSS:This assumes that you want to hide the first column and that the client browser supports the
:first-child
pseudo selector which might not be the case with legacy browsers.So in case you need to support legacy browsers you could use jQuery to apply a hidden style to the header and the rows of the first column or to simply hide them directly:
If you want to have more control I would recommend you checking out the MvcContrib Grid or Telerik Grid.
*强文本*Darin 的解决方案只是部分的,因为“table th:first-child”还将
隐藏“canPage:true”网格页脚
(用于分页) 。解决方案是添加
额外样式
。在“head”部分(或者如果您想将其应用于所有表格,则在 CSS 文件中):
在 Webgrid 部分中:
在 CSS 文件中:
*strong text*Solution from Darin is only partial as the "table th:first-child" will also
hide the "canPage:true" grid footer
(used for paging).Solution is to add
additional styling
.In the "head" section of your (or alternatively in the CSS file if you want to apply it on all tables):
In the Webgrid section:
In the CSS file: