Aspnetcore: Parameter attribute with data annotations

Created on 19 Nov 2018  路  4Comments  路  Source: dotnet/aspnetcore

IMHO it would be great to allow the blazor components to enforce parameter contracts using the existing data annotations; eg.

[Required,Parameter,StringLength(80)]
string Name { get; set; }

this would avoid a lot of boilerplate code with the components and/or replication of feature that exist in data annotation libraries today.

area-blazor

Most helpful comment

Similar ideas (required parameters) are already planned here https://github.com/aspnet/Blazor/issues/1#issuecomment-363034967
Full validation (not related to parameters) is discussed here aspnet/AspNetCore#5460.

All 4 comments

I think it is a bad idea to mix between the two. The Parameter attribute fulfills a different functionality than that of the data annotations. And the Parameter attribute is specific to Blazor.

IMHO I believe the Blazor Parameter attribute represents the component view state and with that in mind data annotations are in fact the correct attributes to use with Blazor parameters/data bindings to enforce parameter/model validation on both client and server using common/shared logic by way of the existing validations.

@enetstudio yes, the Parameter attribute is specific to Blazor; again IMHO there is nothing stopping Blazor from understanding the existing DataAnnonations and applying/generating checks accordingly. I'm not suggesting the Blazor ParameterAttribute be moved/changed.

Similar ideas (required parameters) are already planned here https://github.com/aspnet/Blazor/issues/1#issuecomment-363034967
Full validation (not related to parameters) is discussed here aspnet/AspNetCore#5460.

Validation is being tracked in aspnet/AspNetCore#5460.

FYI the syntax [Parameter, Required] means the same thing as [Parameter][Required] so will work, assuming there ends up being a validation system that works with DataAnnotations attributes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rmarinho picture rmarinho  路  78Comments

Rast1234 picture Rast1234  路  104Comments

zorthgo picture zorthgo  路  136Comments

moodya picture moodya  路  153Comments

KerolosMalak picture KerolosMalak  路  269Comments