次のコードが機能しています
[Required(ErrorMessage = "Price is required.")]
[Range(typeof(Decimal), "1", "9999", ErrorMessage = "Price xx.xx")]
public decimal? productPrice { get; set; }
Price = EMPTY Field を指定してページを送信すると、「Price is required.」というエラー メッセージが表示されます。Price = over 9999 エラー メッセージは「Price xx.xx」です。
しかし、「aaaa」と入力すると、 「The field productPrice must be a number.」というエラー メッセージが表示されます。
入力が正しくない場合、メッセージを変更するにはどうすればよいですか? のように:「価格は 1 ~ 9999 の小数/数値である必要があります。
----更新:---- 以下のコードは動作しました
NULL、10 進数ではなく、範囲内、ただし「.1」では機能しません。
[Required(ErrorMessage = "Price is required.")]
[RegularExpression(@"[0-9]*\.?[0-9]+", ErrorMessage = "Price must be a Numbers only.")]
[Range(typeof(Decimal), "1", "9999", ErrorMessage = "Price must be a decimal/number between {1} and {2}.")]
public decimal? productPrice { get; set; }