如果我有以下内容: [Range(0,120)]public int QtyOnHand { get; set; } 如何添加错误消息来说出所需的范围? RangeAttribute有一个可以设置的ErrorMessage: [Range (0, 120, ErrorMessage = "Quantity on hand must be
[Range(0,120)] public int QtyOnHand { get; set; }
如何添加错误消息来说出所需的范围?
RangeAttribute有一个可以设置的ErrorMessage:[Range (0, 120, ErrorMessage = "Quantity on hand must be between {1} and {2}.")] public int QtyOnHand { get; set; }
通过使用{1}和{2},您不必在数字更改时不断更改字符串. {0}用于该字段的名称.这可以伴随DisplayNameAttribute:
[DisplayName ("Quantity on Hand")] [Range (0, 120, ErrorMessage = "{0} must be between {1} and {2}.")] public int QtyOnHand { get; set; }