Language

EditContext Class

Definition

Holds metadata related to a data editing process, such as flags to indicate which fields have been modified and the current set of validation messages.

public ref class EditContext sealed
public sealed class EditContext
type EditContext = class
Public NotInheritable Class EditContext
Inheritance
EditContext

Constructors

Name Description
EditContext(Object)

Constructs an instance of EditContext.

Properties

Name Description
Model

Gets the model object for this EditContext.

Properties

Gets a collection of arbitrary properties associated with this instance.

ShouldUseFieldIdentifiers

Gets whether field identifiers should be generated for <input> elements.

Methods

Name Description
Field(String)

Supplies a FieldIdentifier corresponding to a specified field name on this EditContext's Model.

GetValidationMessages()

Gets the current validation messages across all fields.

This method does not perform validation itself. It only returns messages determined by previous validation actions.

GetValidationMessages(Expression<Func<Object>>)

Gets the current validation messages for the specified field.

This method does not perform validation itself. It only returns messages determined by previous validation actions.

GetValidationMessages(FieldIdentifier)

Gets the current validation messages for the specified field.

This method does not perform validation itself. It only returns messages determined by previous validation actions.

IsModified()

Determines whether any of the fields in this EditContext have been modified.

IsModified(Expression<Func<Object>>)

Determines whether the specified fields in this EditContext has been modified.

IsModified(FieldIdentifier)

Determines whether the specified fields in this EditContext has been modified.

IsValid(Expression<Func<Object>>)

Determines whether the specified fields in this EditContext has no associated validation messages.

IsValid(FieldIdentifier)

Determines whether the specified fields in this EditContext has no associated validation messages.

IsValidationFaulted()

Returns true if the most recent form-level pass faulted (a registered validation task threw), as opposed to merely producing validation messages. A subsequent successful pass clears it; a caller-cancelled ValidateAsync(CancellationToken) pass preserves it. For per-field faults use the IsValidationFaulted(FieldIdentifier) overload.

IsValidationFaulted(FieldIdentifier)

Returns true if the specified field's last async validation faulted (threw a non-cancellation exception).

IsValidationFaulted<TField>(Expression<Func<TField>>)

Returns true if the field identified by the accessor expression's last async validation faulted (threw a non-cancellation exception).

IsValidationPending()

Returns true if a form-level ValidateAsync(CancellationToken) pass is currently in flight, for driving form-wide UI such as disabling a submit button. Does not consider per-field pending tasks; use the IsValidationPending(FieldIdentifier) overload for those.

IsValidationPending(FieldIdentifier)

Returns true if the specified field has a pending async validation task. The task stays "pending" until the framework's observer has settled its outcome, so a consumer that waits for this to become false is guaranteed to also see the final IsValidationFaulted(FieldIdentifier) value.

IsValidationPending<TField>(Expression<Func<TField>>)

Returns true if the field identified by the accessor expression has a pending async validation task.

MarkAsUnmodified()

Clears all modification flags within this EditContext.

MarkAsUnmodified(FieldIdentifier)

Clears any modification flag that may be tracked for the specified field.

NotifyFieldChanged(FieldIdentifier)

Signals that the value for the specified field has changed.

NotifyValidationStateChanged()

Signals that some aspect of validation state has changed.

RegisterAsyncFieldValidator(FieldIdentifier, Func<CancellationToken,Task>)

Registers an asynchronous validation for a specific field. The validator is invoked immediately with a CancellationToken owned by this EditContext, and the returned Task is tracked for IsValidationPending(FieldIdentifier) and IsValidationFaulted(FieldIdentifier). A validation already tracked for the field is cancelled and replaced.

Validate()
Obsolete.

Validates this EditContext synchronously.

ValidateAsync(CancellationToken)

Validates this EditContext asynchronously, awaiting any validation tasks that handlers register via AddAsyncValidator(Func<CancellationToken,Task>).

Events

Name Description
OnFieldChanged

An event that is raised when a field value changes.

OnValidationRequested

An event that is raised when validation is requested. Validator components subscribe to this event to perform validation.

OnValidationStateChanged

An event that is raised when validation state has changed.

Extension Methods

Name Description
AddDataAnnotationsValidation(EditContext)
Obsolete.

Adds DataAnnotations validation support to the EditContext.

EnableDataAnnotationsValidation(EditContext, IServiceProvider)

Enables DataAnnotations validation support for the EditContext.

EnableDataAnnotationsValidation(EditContext)
Obsolete.

Enables DataAnnotations validation support for the EditContext.

FieldCssClass(EditContext, FieldIdentifier)

Gets a string that indicates the status of the specified field as a CSS class.

FieldCssClass<TField>(EditContext, Expression<Func<TField>>)

Gets a string that indicates the status of the specified field as a CSS class. This will include some combination of "modified", "valid", or "invalid", depending on the status of the field.

SetFieldCssClassProvider(EditContext, FieldCssClassProvider)

Associates the supplied FieldCssClassProvider with the supplied EditContext. This customizes the field CSS class names used within the EditContext.

Applies to