This is a migrated thread and some comments may be shown as answers.

TimeStamp (RowVersion) column passing NULL model.TimeStamp when inline editing

2 Answers 544 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Beau
Top achievements
Rank 1
Beau asked on 28 Jun 2013, 05:18 AM
Model.RowVersion (TimeStamp) field is NULL when inline editing a row that includes a TimeStamp byte[] field, when inspecting the Model.RowVersion value in the UPDATE Controller action. 

I require this field because I am doing concurrency checking on the database when I update a row?

To get around this I will probably change the database data type from a TimeStamp to a UniqueIdentifier (GUID) or INT see: http://stackoverflow.com/questions/1687555/version-number-or-timestamp-for-optimistic-concurrency
columns.Bound(f => f.FluidID).Title("ID").Width(50).Hidden();
columns.Bound(f => f.Name).Title("Name");
columns.Bound(f => f.Code).Title("Code");
columns.Bound(f => f.Grade).Title("Grade");
columns.Bound(f => f.Manufacturer).Title("Manufacturer");
columns.Bound(f => f.RowVersion).Title("RowVersion").Hidden().IncludeInMenu(false);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(182);
Similar questions here:
http://stackoverflow.com/questions/16043026/kendo-ui-for-asp-net-doesnt-render-byte

http://www.kendoui.com/forums/ui/grid/bind-rowversion-field-to-popup-editor-byte.aspx#boFAeK6aG2OF1P8AAFTdxQ

http://www.kendoui.com/forums/mvc/general-discussions/683462-byte-array-rowversion-doesn-t-render-properly.aspx


2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 28 Jun 2013, 06:57 AM
Hello,

 The attached project shows how to serialize a timestamp. The thing is to serialize it to a Base64 string:

[Timestamp]
public Byte[] RowVersion { get; set; }
public string RowVersionBase64
        {
            get
            {
                return Convert.ToBase64String(RowVersion);
            }
        }

Then use the edit event of the grid to set the row version:

<script>
                function grid_edit(e) {
                    var hidden = e.container.find("[name=RowVersion]");
                    e.model.set("RowVersion", e.model.RowVersionBase64);
                    console.log(hidden.val());
                }
</script>

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Adam
Top achievements
Rank 1
answered on 23 Jul 2015, 05:51 PM

This is how I resolved this:

In View Model:

public int Id { get; set; }
public byte[] RowVersion { get; set; }
public string RowVersionBase64
{
get
{
if (RowVersion != null)
{
return Convert.ToBase64String(RowVersion);
}
return null;
}
}

 

The View:

 

@using Kendo.Mvc.UI
@using xx.xx.Mvc.Areas.Wiog.Models
@model AppSettingViewModel
@{
ViewBag.Title = "App Setings";
}
@(Html.Kendo().Grid<AppSettingViewModel>().Name("appSettingsGrid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.Value);
columns.Command(command =>
{
command.Edit();
});
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Events(e => e.Edit("grid_edit"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model => model.Id("Id"))
.Read(read => read.Action("Read", "WiogAppSetting"))
.Update(update => update.Action("Update", "WiogAppSetting"))
)
)
@section Scripts {
<script type="text/javascript">
function grid_edit(e) {
e.model.set("RowVersion", e.model.RowVersionBase64);
}
</script>
}

 

 

 

 

 

 

Tags
Grid
Asked by
Beau
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Adam
Top achievements
Rank 1
Share this question
or