blazor-devexpress-dot-blazor-dot-dxgrid-329960bb.md
Returns the edit context.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public EditContext GetEditContext()
| Type | Description |
|---|---|
| EditContext |
The edit context if the Grid is being edited; otherwise, null.
|
Call this method to obtain the Grid’s edit context. This context allows you to check whether the data item was modified and its field values are valid. If the Grid is not in edit mode, the GetEditContext method returns null.
The following code snippet checks whether the edit row has unsaved changes:
@inject NwindDataService NwindDataService
<DxGrid @ref="Grid"
Data="Data"
KeyFieldName="EmployeeId"
EditModelSaving="OnEditModelSaving"
EditMode="GridEditMode.EditRow">
<Columns>
<DxGridCommandColumn />
<DxGridDataColumn FieldName="FirstName" />
<DxGridDataColumn FieldName="LastName" />
<DxGridDataColumn FieldName="Title" />
<DxGridDataColumn FieldName="HireDate" />
</Columns>
</DxGrid>
@code {
IGrid Grid { get; set; }
IEnumerable<object> Data { get; set; }
NorthwindContext Northwind { get; set; }
async Task OnEditModelSaving(GridEditModelSavingEventArgs e) {
if (Grid.GetEditContext().IsModified()) {
// Save changes to the database
}
}
// ...
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Grid.Northwind {
public partial class Employee {
public int EmployeeId { get; set; }
[Required]
public string LastName { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string Title { get; set; }
public string TitleOfCourtesy { get; set; }
public Nullable BirthDate { get; set; }
[Required]
[Range(typeof(DateTime), "1/1/2000", "1/1/2020",
ErrorMessage = "HireDate must be between {1:d} and {2:d}")]
public Nullable HireDate { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string HomePhone { get; set; }
public string Extension { get; set; }
public byte[] Photo { get; set; }
public string Notes { get; set; }
public Nullable<int> ReportsTo { get; set; }
public string PhotoPath { get; set; }
public virtual ICollection<Order> Orders { get; set; }
public string Text => $"{FirstName} {LastName} ({Title})";
public string ImageFileName => $"Employees/{EmployeeId}.jpg";
}
}
See Also