Fork me on GitHub

MVC Remote 服务器验证

用此验证必须在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; }

 

posted @ 2018-10-27 08:58  CSharp精选营  阅读(324)  评论(0编辑  收藏  举报
Copyright ©2019 SC2ZZ