码迷,mamicode.com
首页 > Web开发 > 详细

MVC Remote 服务器验证

时间:2018-10-27 10:25:07      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:span   ISE   str   ret   contex   string   public   rem   wget   

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

 

MVC Remote 服务器验证

标签:span   ISE   str   ret   contex   string   public   rem   wget   

原文地址:https://www.cnblogs.com/scc-/p/9860059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!