是否可以在代碼中設置範圍(或任何其他型號DataAnnotations
屬性)並保持所有的DataAnnotations
行爲?MVC set代碼中的數據註釋屬性
即我有一個十進制模型,我想在代碼中設置其最小值(例如在頁面加載時),我可以繼續使用ValidationMessageFor
?
我目前的 「靜態」 模型
[Required]
[DisplayName("Price")]
[RegularExpression(@"[0-9]+(\.[0-9][0-9]?)?$", ErrorMessage = "Invalid price format")]
public decimal MinimumPrice { get; set; }
謝謝!
謝謝MMan,我會檢查一下。 – Salty