如何在ASP.NET MVC4中显示两个不同的错误消息

时间:2013-06-21 08:40:01

标签: asp.net-mvc asp.net-mvc-3 data-annotations

我想显示两条不同的错误消息。首先给出Int64值的必需值和秒值。这是我的代码。

    [Display(Name = "Employee")]
    [Required]
    public Int64 EmployeeId { get; set; }

2 个答案:

答案 0 :(得分:1)

您可以使用RangeAttribute

[Required(ErrorMessage = "Msg1")]
[Range(10, 1000, 
    ErrorMessage = "Value for {0} must be between {1} and {2}.")]
public object Weight;

答案 1 :(得分:0)

您可以在此处使用数据注释扩展:http://dataannotationsextensions.org/

然后按如下方式添加两个注释:

[Required(ErrorMessage = "Employee Id is required")]
[DataAnnotationsExtensions.Integer(ErrorMessage = "Please enter a valid number.")]
public Int64 EmployeeId { get; set; }