更改消息默认@ Html.ValidationMessageFor mvc 4

时间:2013-11-22 17:00:28

标签: c# asp.net-mvc asp.net-mvc-4 razor

我尝试从@Html.ValidationMessageFor更改消息默认值。我可以在哪里查找邮件的文件:The _nameFied field is required.

查看:

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

1 个答案:

答案 0 :(得分:7)

您可以使用Required属性中的ErrorMessage property在模态类的特定属性中执行此操作。

例如:

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