Model with property of EmailAddress attribute doesn't work

Hello,

I try to list users on a grid.

The Razor page is:
    <SfGrid DataSource="@DbContext.Users" Toolbar="@(new List<string>() {"Delete"})">
        <GridEditSettings AllowAdding="false" AllowEditing="false" AllowDeleting="true"/>
        <GridColumns>
            <GridColumn Field=@nameof(User.Name) HeaderText="Name" TextAlign="TextAlign.Center" Width="160"/>
            <GridColumn Field=@nameof(User.Email) ValidationRules="@VRs" HeaderText="Email"/>
        </GridColumns>
    </SfGrid>

The ViewModel:
    public class UsersVM : PageVMBase
    {
        public ValidationRules VRs { get; set; } = new ValidationRules() {Email = true.ToString()}; 
    }

The Model:
    public class User
    {
        [Key]
        public string Id { get; set; }

        [Required(AllowEmptyStrings = false)]
        public string FirstName { get; set; }

        [Required(AllowEmptyStrings = false)]
        public string LastName { get; set; }

        public string Name => $"{FirstName} {LastName}";

        [EmailAddress]
        public string Email { get; set; }

        public string Password { get; set; }
    }

So nothing special.

The issue: when try to show the Email column the page breaks with the following error:

blazor.server.js:15 [2020-07-28T14:26:34.238Z] Error: System.InvalidCastException: Unable to cast object of type 'System.Boolean' to type 'System.String'.
   at Syncfusion.Blazor.Grids.ValidationRules.ToInstance(IDictionary`2 dictionary)
   at Syncfusion.Blazor.Grids.GridAnnotation.MapAnnotation(GridColumn columns, Type type)
   at Syncfusion.Blazor.Grids.SfGrid`1.Syncfusion.Blazor.Grids.IGrid.AnnotateColumn(GridColumn column)
   at Syncfusion.Blazor.Grids.GridColumn.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

Without the EmailAddress attribute it is working well.

I tried to solve it by passing validation rules for the column (not sure it would be the solution), but:
- I couldn't set it on the razor page, just binding from the VM
- How to declare the ValidationRules.Email property? It's a string, but I couldn't find any documentation what is it.

Can you give me a hint what to do? It's a bug or normal behavior?
I am using the latest version: Sf.Blazor v18.2.0.47

3 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team July 29, 2020 11:16 AM UTC

Hi Istvan, 
 
Thanks for contacting Syncfusion support.  
 
Query: “Without the EmailAddress attribute it is working well.”  
 
We have validated the reported issue at our end. Since it is known issue, we have confirmed it as a bug and logged the defect report “Exception thrown when using EmailAddress DataAnnotation” for the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming weekly Patch release which is expected to be rolled out by mid of August, 2020.    
   
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.   
 
 
Until then we appreciate your patience.    
 
Regards,  
Vignesh Natarajan 
 


Marked as answer

IP Istvan Piroska July 29, 2020 05:12 PM UTC

Alright, thank you for the feedback.

Regards,
Istvan


VN Vignesh Natarajan Syncfusion Team July 30, 2020 05:58 AM UTC

Hi Istvan,  

Thanks for the update.  

We will get back to you once our weekly patch release gets successfully rolled out.  

Regards,
Vignesh Natarajan 



Loader.
Up arrow icon