question

HamedVaziri-4770 avatar image
0 Votes"
HamedVaziri-4770 asked YinqiuYao-MSFT commented

Blazor validation not working when using Metadata class!

I am using blazore Server side. Form validation is not working when using Metadata class. I am using scaffolding and my DB models are oftern automatically generated. If i modify the it wipes out all my Dataannotation validations.

Here is the class that i am using :

 public partial class ContactUs_Product_ProductRequests
     {
         [Key]
         public int ProductRequestID { get; set; }
         [StringLength(50)]
         public string CompanyName { get; set; }
         public int? CompanyTypeID { get; set; }
         [StringLength(50)]
         public string AgentName { get; set; }
         [StringLength(50)]
         public string AgentRole { get; set; }
         [StringLength(50)]
         public string AgentTel { get; set; }
         [StringLength(50)]
         public string AgentMobile { get; set; }
         [StringLength(50)]
         public string AgentEmail { get; set; }
         public string Description { get; set; }
         [StringLength(10)]
         public string RequestDate { get; set; }
     }
    
 public class ContactUs_Product_ProductRequestsMetadata
     {
         [Required]
         public string AgentName { get; set; }
     }
    
     [MetadataType(typeof(ContactUs_Product_ProductRequestsMetadata))]
     public partial class ContactUs_Product_ProductRequests
     {
    
     }
dotnet-aspnet-core-blazor
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YinqiuYao-MSFT avatar image
0 Votes"
YinqiuYao-MSFT answered

Hi @HamedVaziri-4770

It seems it is not yet supported for Blazor.

You can see the github issue.

MetadataTypeAttribute doesn't influence DataAnnotations validation result

Best Regards,
Yinqiu Yao





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HamedVaziri-4770 avatar image
0 Votes"
HamedVaziri-4770 answered YinqiuYao-MSFT commented

Thanks for reply
What's the best practice for this situation?
Thanks in advance

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @HamedVaziri-4770 ,you can observe some comments under this github thread, which may inspire you.

0 Votes 0 ·