MVC Remote服务器验证如何实现自动识别?

摘要:用此验证必须在Controller中编写返回值为JsonResult的Action 实体类代码:
用此验证必须在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; }