Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Nullable EmailAddress validation not working

$
0
0

I have two EmailAddress columns in my Debtor model:

[EmailAddress(ErrorMessage = "Contact e-mailadres moet een geldig formaat zijn.")]public string? ContactEmail { get; set; }[EmailAddress(ErrorMessage = "Factuur e-mailadres moet een geldig formaat zijn.")]public string? InvoiceEmail { get; set; }

I get my Debtor from the SQL database with the following method:

Context = _dbContext.CreateDbContext();_debtor = await Context.Debtors?.SingleOrDefaultAsync(c => c.Id == DebtorId);

Within my database, the values of InvoiceEmail and ContactEmail are NULL - not "".

However, when I go to the edit page the columns within my Debtor are "" and not NULL. So when I hit save the validation throws an error "Email must be valid". Within my .net 7 project I used the same model without this issue.

enter image description here

Is something changed in .net 8? How to solve this issue?

I also tried it with the following model columns:

[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Null]")][EmailAddress(ErrorMessage = "Contact e-mailadres moet een geldig formaat zijn.")]public string? ContactEmail { get; set; }[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Null]")][EmailAddress(ErrorMessage = "Factuur e-mailadres moet een geldig formaat zijn.")]public string? InvoiceEmail { get; set; }

Also did not solve the issue.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>