zoukankan      html  css  js  c++  java
  • MVC 模型js远程校验的使用方法

    我们在网站注册的时候往往需要在用户注册完毕的时候显示用户名是否可用,这就要用到模型的远程校验了。具体如下。

         [Required(ErrorMessage = "用户名不能为空"), Remote("ValidateUserName", "CommonWebApi", AreaReference.UseRoot, ErrorMessage = "用户名已被占用")]
            [StringLength(100, ErrorMessage = "{0} 至少包含 {2} 个字符。", MinimumLength = 5)]
            [Display(Name = "用户名")]
            public string UserName { get; set; }
    Remote方法实现了远程校验。

    返回的类型为Bool

     /// <summary>
            /// 找回密码验证用户名是否存在
            /// </summary>
            /// <param name="userName"></param>
            /// <returns></returns>
            public ActionResult VerifyUserName(string userName)
            {
                var user = _userProfileRepository.All().FirstOrDefault(item => item.UserName == userName);
                return Content(user == null ? "false" : "true");
            }
    
            public JsonResult GetAddressByGeo(decimal latitude,decimal longitude)
            {
                var address = _geoCodingInvoker.GetGeoAddressByCoordinate(latitude, longitude);
                return Json(address,JsonRequestBehavior.AllowGet);
            }
    
    
  • 相关阅读:
    Thinkcmf:页面常用函数
    thinkcmf开发--关于控制器
    thinkcmf 常用操作
    Thinkcmf 二次开发
    Sublime Text 3 快捷键精华版
    php动态更改post_max_size, upload_max_filesize等值
    Jquery使用小技巧
    jQuery常用方法和函数
    三层架构
    JDBC
  • 原文地址:https://www.cnblogs.com/WZH75171992/p/4560536.html
Copyright © 2011-2022 走看看