ASP.NET WEB API 自定义模型校验过滤器

时间:2022-06-01 08:42:23

public ResponseProtocol Register(RegisterCustomerModel registerCustomerModel) { if (!ModelState.IsValid) { return new ResponseProtocol((int)ResponseResultEnum.ValidateError, ModelState.ToErrorMessage(), string.Empty); } Customer customer = new Customer { Name = registerCustomerModel.Name, Phone = registerCustomerModel.Phone, WeiXinNo = registerCustomerModel.WeiXinNo, Company = registerCustomerModel.Company, UpdateTime = DateTime.Now }; _customerService.Add(customer); return new ResponseProtocol((int)ResponseResultEnum.Success, "注册成功", string.Empty); }