Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The message The value '' is not valid for #54577

Closed
1 task done
zandiarash opened this issue Mar 17, 2024 · 1 comment
Closed
1 task done

The message The value '' is not valid for #54577

zandiarash opened this issue Mar 17, 2024 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@zandiarash
Copy link

zandiarash commented Mar 17, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a Blazor web application which uses System.ComponentModel.DataAnnotations attribute for validation in a registration form .
I have a property named NationalCode which is nullable long
I did not added [Required] attribute above my NationalCode property
But when I want to submit the form if I leave the field NationalCode empty this validation message appears :
"The value '' is not valid for 'NationalCode'."

If I change my code and add [Required] attribute like this :

[Required(ErrorMessage = "Please Enter your national code", AllowEmptyStrings = true)]
public long? NationalCode { get; set; } = null;

Two message appears :

- "The value '' is not valid for 'NationalCode'."
- "Please Enter your national code"

This is my codes :

<div class="form-floating">
    <InputNumber @bind-Value="Input.NationalCode" autocomplete="nationalCode" aria-required="true" />
    <label for="family">NationalCode</label>
    <ValidationMessage For="() => Input.NationalCode" class="text-danger" />
</div>

 private sealed class InputModel
 {
     public long? NationalCode { get; set; }
 }

Expected Behavior

But I want only my message appear.
Where is the first message come from ?
How can I disable it ?

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.3

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Mar 17, 2024
@javiercn
Copy link
Member

@zandiarash thanks for contacting us.

This is a dupe of #52195

@javiercn javiercn added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants