ModelState.IsValid

model内的设置如下所示:

/// <summary>

        /// 取得或设置邮编

        /// </summary>

        [RegularExpression(@"(^[1-9]\d{5}$)", ErrorMessage = "邮编不符合规范!")]

        public string Zip

        {

            get

            {

                return _Zip;

            }

            set

            {

                if (_Zip != value)

                {

                    _Zip = string.IsNullOrEmpty(value) ? value : value.Trim();

                    OnPropertyChanged("Zip");

                }

            }

        }
 /// <summary>

        /// 添加人员

        /// </summary>

        /// <param name="memberVO">客户端人员对象</param>

        /// <returns></returns>

        [HttpPost]

        public dynamic AddMember(MemberVO memberVO)

        {

            if (ModelState.IsValid)

            {

                var member = SaveMember(memberVO);

                HttpResponseMessage httpResponseMessage = Request.CreateResponse(HttpStatusCode.Created, member.MemberToMemberVO(User, Database));



                return httpResponseMessage;

            }

            Log(ModelState);

            return Request.CreateResponse(HttpStatusCode.InternalServerError);

        }

相当于服务器对客户端model的一种验证。model实例如在服务器端不符合要求则会报错。

你可能感兴趣的:(Model)