Base solution for your next web application
Open Closed

Model Binding - Custom Message #11627


User avatar
0
ISL created

Dear ASP.NET zero support

If we take the example https://docs.aspnetzero.com/en/aspnet-core-angular/latest/Developing-Step-By-Step-Angular-Creating-New-Person However for the CreatePersonInput class I add a new property

public class CreatePersonInput
{
    [Required]
    [MaxLength(PersonConsts.MaxNameLength)]
    public string Name { get; set; }

    [Required]
    [MaxLength(PersonConsts.MaxSurnameLength)]
    public string Surname { get; set; }

    [EmailAddress]
    [MaxLength(PersonConsts.MaxEmailAddressLength)]
    public string EmailAddress { get; set; }

    public bool isCustomer { get; set; }
}

If I pass on string for the isCustomer it will return an error stating the passed on value is incorrect. How can we modify this error message? We attempted multiple solutions and custom validation however as the model binding validation happens before and String != Boolean our custom validation is never triggered.

Kind Regards Kim


1 Answer(s)