用此验证必须在Controller中编写返回值为JsonResult的Action
1 public JsonResult CheckUserName(string UserName) 2 { 3 EFHelper<StudentDBEntities> dbContext = EFHelper<StudentDBEntities>.GetInstance(); 4 UserInfo result = dbContext.GetSingle<UserInfo>(item => item.UserName == UserName); 5 bool isExists; 6 if (result != null) 7 { 8 isExists = false; 9 return Json(isExists, JsonRequestBehavior.AllowGet); 10 } 11 else 12 { 13 isExists = true; 14 return Json(isExists, JsonRequestBehavior.AllowGet); 15 } 16 17 }
实体类代码:
1 [Remote("CheckUserName", "User", ErrorMessage = "用户名已存在")] 2 public string UserName { get; set; }
原文地址:https://www.cnblogs.com/scc-/p/9860059.html
时间: 2024-10-18 07:04:33