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

3 posts, 1 answers
  1. Beau
    Beau avatar
    19 posts
    Member since:
    Mar 2011

    Posted 28 Jun 2013 Link to this post

    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. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Jun 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Adam
    Adam avatar
    1 posts
    Member since:
    Apr 2014

    Posted 23 Jul 2015 in reply to Atanas Korchev Link to this post

    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>
    }

     

     

     

     

     

     

Back to Top