Asp.net mvc 4 是否使用其他属性的值设置数据注释最小属性消息?
我的视图模型(C#MVC4)中有一个对象列表。 对象是这样的:Asp.net mvc 4 是否使用其他属性的值设置数据注释最小属性消息?,asp.net-mvc-4,data-annotations,Asp.net Mvc 4,Data Annotations,我的视图模型(C#MVC4)中有一个对象列表。 对象是这样的: public int IdContainer { get; set; } public string DisplayName { get; set; } [Min(1, ErrorMessage = "The Quantity must be greather than 0.")] public int Quantity { get; set; } The Quantity must be greather than 0. The
public int IdContainer { get; set; }
public string DisplayName { get; set; }
[Min(1, ErrorMessage = "The Quantity must be greather than 0.")]
public int Quantity { get; set; }
The Quantity must be greather than 0.
The Quantity must be greather than 0.
问题是,我正在列表中显示错误消息列表,因此,如果列表中有多个对象,并且两个对象的数量均为0,则会出现两条相同的错误消息,如下所示:
public int IdContainer { get; set; }
public string DisplayName { get; set; }
[Min(1, ErrorMessage = "The Quantity must be greather than 0.")]
public int Quantity { get; set; }
The Quantity must be greather than 0.
The Quantity must be greather than 0.
我可以通过修改ErrorMessage并将DisplayName属性放入消息中来改变这些消息吗