4

I try to change the message default from @Html.ValidationMessageFor. Where is the file who i can chage the message: The _nameFied field is required.

View:

@Html.ValidationMessageFor(model => model.NumDoc,"", new { @class = "error-input"})

1 Answer 1

7

You can do it in your modal class's specific property using the ErrorMessage property in the of Required attribute.

Ex:

public class MyClass{

    [Required(ErrorMessage = "My validation error message goes here")] //give your validation message here
    [Display(Name = "My display name")] //Give your display name here
    public int NumDoc{ get; set; }
}
Sign up to request clarification or add additional context in comments.

4 Comments

i can also put the field name in the message?
@CesarMiguel What do you mean by new migration? How does your class look like?
@CesarMiguel Yes you can add [DisplayName("My Name")] attribute on top of your property as well.
Yes, ty [Key, Column(Order = 1)] [Display(Name = "Nº Documento")] [Required(ErrorMessage = "É obrigatório")] public int NumDoc { get; set; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.