Skip to content

Blazor Add validation error/message for field #40357

@omuleanu

Description

@omuleanu

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

is it possible (is there plans to implement) to add a validation error like in MVC AddModelError(key, errorMessage) ?

for now I have temporary workaround which looks like this:

public class CustomValid : ValidationAttribute
{
    public override bool IsValid(object value)
    {
        if (value is null) return true;
        
        ErrorMessage = (string)value;
        return false;
    }
}

ViewModel:

[CustomValid]
public string Vld1 { get; set; }

save code:

input.Vld1 = input.Name == "Foo" ? "Name not unique" : null;
if (!editContext.Validate()) ...

Describe the solution you'd like

EditContext.AddFieldError(fieldName, errorMessage)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions