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);
            }
    
    
  • 相关阅读:
    二分图最大匹配的K&#246;nig定理及其证明
    HDOJ 2389 Rain on your Parade
    HDOJ 1083 Courses
    HDOJ 2063 过山车
    POJ 1469 COURSES
    UESTC 1817 Complete Building the Houses
    POJ 3464 ACM Computer Factory
    POJ 1459 Power Network
    HDOJ 1532 Drainage Ditches
    HDU 1017 A Mathematical Curiosity
  • 原文地址:https://www.cnblogs.com/WZH75171992/p/4560536.html
Copyright © 2011-2022 走看看