MVC Remote 服务器验证
程序员文章站
2022-04-29 14:14:04
用此验证必须在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; }
推荐阅读