參數(shù)驗(yàn)證實(shí)現(xiàn)
在做服務(wù)端開(kāi)發(fā)時(shí)經(jīng)常需要對(duì)客戶端傳入的參數(shù)進(jìn)行合法性驗(yàn)證,在ASP.NET Core中通常會(huì)使用如下方式:
public class LoginModel { [Required(ErrorMessage = "賬號(hào)不能為空")] public string Account { get; set; } [StringLength(12, MinimumLength = 6, ErrorMessage = "密碼長(zhǎng)度應(yīng)介于6-12個(gè)字符之間")] public string Password { get; set; } }