New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Update Grids by Using timestamp Property
Environment
Product | Telerik UI for ASP.NET MVC Grid |
Product version | 2025.1.227 |
Description
How can I update Grids by using timestamp
property?
Solution
You can achieve this requirement using the following implementation:
-
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"); }) )
-
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); } } } }
-
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
- ASP.NET MVC Grid Documentation
- ASP.NET MVC Grid Demos
- ASP.NET MVC Grid Product Page
- Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)
- Telerik UI for ASP.NET MVC Forums