public class StudentModel
    {
        [Display(Name="学生编号")]
        public int StuId { set; get; }

        [Required(ErrorMessage="请输入学生姓名!")]
        [StringLength(10,ErrorMessage="姓名长度不能长于10!")]
        [Display(Name="学生姓名")]
        [Remote("ValirStuName","Student",HttpMethod="Post",ErrorMessage="学生姓名已经存在!")]
        public string StuName { set; get; }

        [Display(Name="学生Email")]
        [DataType(DataType.EmailAddress)]
        public string StuSex { set; get; }
        
        [Display(Name="班级ID")]
        public int Gid { set; get; }

        [Display(Name="学生描述")]
        public string StuDesc { set; get; }
    }

Controller:

        /// <summary>
        /// 参数名称与Model中的名称一致
        /// </summary>
        /// <param name="StuName"></param>
        /// <returns></returns>
        public ActionResult ValirStuName(string StuName)
        {
            return Json(true);
            //return Json("你所填写的用户名,已经存在了!");//当返回不为true时,则默认认为验证失败及自定义的错误信息
            //return new JsonResult { Data=false,JsonRequestBehavior=JsonRequestBehavior.AllowGet };
        }

 

相关文章:

  • 2021-07-18
  • 2022-12-23
  • 2021-11-09
  • 2022-02-17
  • 2022-12-23
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-09-14
  • 2022-12-23
  • 2021-05-26
相关资源
相似解决方案