CesarMiguel
CesarMiguel

Reputation: 3830

Change message default @Html.ValidationMessageFor mvc 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"})

Upvotes: 4

Views: 12011

Answers (1)

PSL
PSL

Reputation: 123739

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; }
}

Upvotes: 7

Related Questions