欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MVC Remote 服务器验证

程序员文章站 2022-08-29 08:17:54
用此验证必须在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; }