New to Telerik UI for ASP.NET MVCStart a free 30-day trial

Update Grids by Using timestamp Property

Environment

ProductTelerik UI for ASP.NET MVC Grid
Product version2025.1.227

Description

How can I update Grids by using timestamp property?

Solution

You can achieve this requirement using the following implementation:

  1. Create an editable Grid:

    Razor
    @(Html.Kendo().Grid<Telerik.Examples.Mvc.Areas.GridTimestamp.Models.Product>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.ProductID);
            columns.Bound(p => p.ProductName);
            columns.Bound(p => p.RowVersionString);
            columns.Command(command => command.Edit());
        })
        .DataSource(source =>
        {
            source.Ajax()
            .Model(model =>
            {
                model.Id(p => p.ProductID);
                model.Field(p => p.ProductID).Editable(false);
            })
            .Read("Read", "Home")
            .Update("Update", "Home");
        })
    )
  2. Define the timestamp Model property:

    C#
    public class Product
    {
        [Key]
        [DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int ProductID { get; set; }
        public string ProductName { get; set; }
    
        [Timestamp]
        public byte[] RowVersion { get; set; }
    
        [NotMapped]
        public string RowVersionString
        {
            get
            {
                if (this.RowVersion != null)
                {
                    return Convert.ToBase64String(this.RowVersion);
                }
    
                return string.Empty;
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    this.RowVersion = null;
                }
                else
                {
                    this.RowVersion = Convert.FromBase64String(value);
                }
            }
        }
    }
  3. Define the Update Action:

    C#
    public ActionResult Update(Product product)
    {
        if (ModelState.IsValid)
        {
            context.Products.Attach(product);
            context.Entry(product).State = EntityState.Modified;
            context.SaveChanges();
        }
    
        return Json(new[] { product }.ToDataSourceResult(new DataSourceRequest(), ModelState));
    }

To review the complete example, refer to the project on how to update the Telerik UI Grid in ASP.NET MVC applications by using the timestamp property.

More ASP.NET MVC Grid Resources

See Also