Вопрос

Я хочу добавить удостоверение личности на элементы «TR» GRID MVCCONTRIB I Build:

<tr id="0"/>
<tr id="1"/>
.

Так что, если таблица содержит 10 строк, идентификаторы от 0 до 9.

Один из способов - добавить дополнительный элемент для моего объекта, чтобы сохранить это значение, а затем создать это в качестве скрытого столбца с идентификатором в качестве значения этого элемента - не очень элегантно.

Есть ли более элегантный способ сделать это? Спасибо

У меня это далеко, но теперь он жалуется на линию рендеринга, любые идеи?

@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>()));
.

}

Это было полезно?

Решение

You could transform the model to add it a row index and then use the RowAttributes method:

@model IEnumerable<MyViewModel>
@(Html
    .Grid(Model.Select((item, index) => new { Item = item, Index = index }))
    .Columns(column =>
    {
        column.For(x => x.Item.Foo);
        column.For(x => x.Item.Bar);
    })
    .RowAttributes(x => new Hash(id => string.Format("id{0}", x.Item.Index)))
)

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:

<table class="grid">
    <thead>
        <tr>
            <th>Foo</th>
            <th>Bar</th>
        </tr>
    </thead>
    <tbody>
        <tr id="id0" class="gridrow">
            <td>foo 1</td>
            <td>bar 1</td>
        </tr>
        <tr id="id1" class="gridrow_alternate">
            <td>foo 2</td>
            <td>bar 2</td>
        </tr>
        <tr id="id2" class="gridrow">
            <td>foo 3</td>
            <td>bar 3</td>
        </tr>
    </tbody>
</table>

Другие советы

You can always show hide columns without adding id to particular row or columns like below

$(".mvcGridDollarHeader th:nth-child(16)").hide();
$(".mvcGrid td:nth-child(16)").hide();

Where mvcGrid is tableStyle and mvcGridDollarHeader is header style.

@grid1.GetHtml(
    tableStyle: "mvcGrid",
    displayHeader: true,
    emptyRowCellValue: "",
    headerStyle: "mvcGridDollarHeader",
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top