Skip to content

[ClientValidation]

IntelliTect.Coalesce.DataAnnotations.ClientValidationAttribute

The ClientValidation attribute is used to control the behavior of client-side model validation and to add additional client-only validation parameters. Database validation is available via standard System.ComponentModel.DataAnnotations annotations.

These propagate to the client as validations in TypeScript via generated Metadata and ViewModel rules. Any failing validation rules prevent saves from going to the server.

WARNING

This attribute controls client-side validation only. To perform server-side validation, create a custom Behaviors class for your types and/or place C# validation attributes on your models. Read More.

Example Usage

c#
public class Person
{
    public int PersonId { get; set; }

    [ClientValidation(IsRequired = true, AllowSave = true)]
    public string FirstName { get; set; }

    [ClientValidation(IsRequired = true, AllowSave = false, MinLength = 1, MaxLength = 100)]
    public string LastName { get; set; }
}

Properties

public string ErrorMessage { get; set; }

Set an error message to be used if any client validations fail

Validation Rule Properties

 

In addition to the following properties, you also customize validation on a per-instance basis of the ViewModels using the Rules/Validation methods.

c#
public bool IsRequired { get; set; }
public double MinValue { get; set; } = double.MaxValue;
public double MaxValue { get; set; } = double.MinValue;
public double MinLength { get; set; } = double.MaxValue;
public double MaxLength { get; set; } = double.MinValue;
public string Pattern { get; set; }
public bool IsEmail { get; set; }
public bool IsPhoneUs { get; set; }

Coalesce is a free and open-source framework created by IntelliTect to fill our desire to create better apps, faster. IntelliTect is a high-end software architecture and development consulting firm based in Spokane, Washington.

If you're looking for help with your software project, whether it be a Coalesce application, other technologies, or even just an idea, reach out to us at info@intellitect.com — we'd love to start a conversation! Our clients range from Fortune 100 companies to local small businesses and non-profits.