StellarAdmin is still in development. We'd love for you to try it out and get your feedback, but please be advised that you may run into bugs. Changes to public APIs may also occur.

Validating your resources

Introduction

StellarAdmin integrates with ASP.NET Core model validation. You can define validation for your resources using the following methods:

Validating resources

When using the DbContextDataSource, StellarAdmin will automatically perform validation on your resources before updating the entity on your database context. However, when you are making use of the DelegateDataSource, you will need to perform the validation yourself. StellarAdmin provides a FormHelpers class with a ValidateResource method that you can call.

Validating actions

StellarAdmin automatically performs validation on the model specified for form-based actions. All you need to do is to specify validation rules for your model using one of the three methods mentioned at earlier in this document. In the example below, the PublishDate property of the action model has a Required attribute specified to ensure that the user specifies a value before the action will be executed.

public class PublishBlogPost : FormResourceAction<PublishBlogPost.PublishBlogPostModel>
{
    public class PublishBlogPostModel
    {
        [Required]
        public DateTime PublishDate { get; set; }
    }

    protected override async Task<ActionResult> Execute(object[] keys, PublishBlogPostModel model, FormActionRequestContext context)
    {
        //...
    }
}

Error display

If your resource or action model has validation errors, StellarAdmin will highlight the fields containing validation errors and display the error message below the field.

Validation errors displayed in the StellarAdmin UI