我想向我构建的 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>()));
}