Search code examples
asp.net-coredata-bindingteleriktelerik-gridtelerik-mvc

Pass hidden fields in Telerik grid row


I use Telerik grid in my asp.net core application.

I have a list of Orders, I need to bind some fields (like CreatedBy, by eg.) to be hidded, in order to get them when the user updates them.

I saw similar question without an answer.

my Code

@(Html.Kendo()
.Grid(Model)
.Name("Orders")
.Columns(columns =>
{
    columns.Bound(c => c.Name).Width(190);
    columns.Bound(c => c.CreatedById).Hidden();
    columns.Bound(c => c.ModifiedById).Hidden();
    columns.Command(command => { command.Destroy(); }).Width(100);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(dataSource => dataSource
    .Ajax()
    .Batch(true)
    .PageSize(20)
    .ServerOperation(false)
    .Events(events => events.Error("error_handler"))
    .Model(model => {
        model.Id(s => s.Id);
    })
    .Create(update => update.Action("BatchCreate", "Orders"))
    .Read(read => read.Action("BatchRead", "Orders"))
    .Update(update => update.Action("BatchUpdate", "Orders"))
    .Destroy(update => update.Action("BatchDestroy", "Orders"))
)
)

Solution

  • Finally, solved it by adding the hidden fields to the datasource model:

    .Columns(columns =>
    {
        columns.Bound(c => c.Name).Width(190); // visible
        columns.Bound(c => c.HiddenId).Hidden();
        columns.Bound(c => c.HiddenOtherFiled).Hidden();
    })
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Events(events => events.Error("error_handler"))
        .Model(model =>
        {
            model.Id(s => s.Id);
            model.Field(s => s.HiddenId);
            model.Field(s => s.HiddenOtherFiled);
        })