mvccontrib grid - 如何添加; ID
我想向我构建的 mvccontrib 网格的“tr”元素添加一个 id:
<tr id="0"/>
<tr id="1"/>
因此,如果表包含 10 行,则 id 为 0 到 9。
一种方法是向我的实体添加一个附加项来存储该值然后将其创建为隐藏列,并将 id 作为该项目的值 - 不是很优雅。
有没有更优雅的方法来做到这一点? 谢谢,
我已经走到这一步了,但现在它在 RenderUsing 行抱怨,有什么想法吗?
@model IEnumerable<Tens.Models.UserPreviousNamesView>
<div class="demo_jui">
@{
var userId = 0;
foreach (var item in Model)
{
userId = item.Id;
break;
}
@(Html.Grid(Model.Select((item,index) => new { Item = item, Index = index}))
.Columns(col =>
{
col.For(p => p.Item.Title);
col.For(p => p.Item.Name);
col.Custom(@<text>
@Ajax.ActionLink("Delete", "DeleteUserPreviousName", "Summary", null, null, new { id = item.Item.Id, @class = "deleteUserPreviousName" })
</text>).Encode(false);
})
.RowAttributes(p => new Hash(Id => "id"+p.Item.Index.ToString()))
.Attributes(Id => "userPreviousNamesTable")
.Empty("You currently have no Previous Names.")
.RenderUsing(new Tens.GridRenderers.UserPreviousNamesGridRenderer<Tens.Models.UserPreviousNamesView>()));
}
I want to add an id to the "tr" elements of the mvccontrib grid I build:
<tr id="0"/>
<tr id="1"/>
so if the table contains 10 rows, the ids are 0 through to 9.
One way is to add an additional item to my entity to store this value and then create this as a hidden column with the id as the value of this item - not very elegant.
Is there a more elegant way to do this?
Thanks
I've got this far but now it complains at the RenderUsing line, any ideas?
@model IEnumerable<Tens.Models.UserPreviousNamesView>
<div class="demo_jui">
@{
var userId = 0;
foreach (var item in Model)
{
userId = item.Id;
break;
}
@(Html.Grid(Model.Select((item,index) => new { Item = item, Index = index}))
.Columns(col =>
{
col.For(p => p.Item.Title);
col.For(p => p.Item.Name);
col.Custom(@<text>
@Ajax.ActionLink("Delete", "DeleteUserPreviousName", "Summary", null, null, new { id = item.Item.Id, @class = "deleteUserPreviousName" })
</text>).Encode(false);
})
.RowAttributes(p => new Hash(Id => "id"+p.Item.Index.ToString()))
.Attributes(Id => "userPreviousNamesTable")
.Empty("You currently have no Previous Names.")
.RenderUsing(new Tens.GridRenderers.UserPreviousNamesGridRenderer<Tens.Models.UserPreviousNamesView>()));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以转换模型以添加行索引,然后使用
RowAttributes
方法:此外,我还使用
id
关键字预先添加了 id,因为 HTML 中的 id 无法统计带有示例中所示的数字。示例输出:
You could transform the model to add it a row index and then use the
RowAttributes
method:Also I have pre-pended the id with the
id
keyword as ids in HTML cannot statr with a number as shown in your example.Sample output:
您始终可以显示隐藏列,而无需向特定行或列添加 id,如下所示
,其中
mvcGrid
是 tableStyle,mvcGridDollarHeader
是标题样式。You can always show hide columns without adding id to particular row or columns like below
Where
mvcGrid
is tableStyle andmvcGridDollarHeader
is header style.