EditContext Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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 |
|---|---|
| AddValidationTask(FieldIdentifier, Task, CancellationTokenSource) |
Registers an async validation task for a specific field. The task is tracked for
pending/faulted state queries via IsValidationPending(FieldIdentifier)
and IsValidationFaulted(FieldIdentifier). If a task is already tracked
for this field, the previously registered CancellationTokenSource is cancelled
and the new task replaces it. The EditContext takes ownership of the supplied
|
| 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 |
| IsValidationFaulted(FieldIdentifier) |
Returns |
| IsValidationFaulted<TField>(Expression<Func<TField>>) |
Returns |
| IsValidationPending() |
Returns |
| IsValidationPending(FieldIdentifier) |
Returns |
| IsValidationPending<TField>(Expression<Func<TField>>) |
Returns |
| 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. |
| Validate() |
Validates this EditContext. |
| ValidateAsync(CancellationToken) |
Validates this EditContext asynchronously.
Cancels any pending field-level async validation tasks, invokes the synchronous
OnValidationRequested handlers, then invokes and awaits the asynchronous
OnValidationRequestedAsync handlers concurrently. Exceptions from synchronous
handlers propagate to the caller, matching Validate(). Any non-cancellation
exception thrown by an asynchronous handler is contained: the form is marked as faulted
(observable via the parameterless IsValidationFaulted()) and the method
returns |
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 synchronous validation. |
| OnValidationRequestedAsync |
An async event that is raised when validation is requested. Validator components subscribe to this event to perform async validation (e.g., database lookups, remote API calls). Handlers are awaited by ValidateAsync(CancellationToken). Validate() also invokes these handlers but requires each to complete synchronously; if any returns an incomplete Task, Validate() throws InvalidOperationException. |
| 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. |