zoukankan      html  css  js  c++  java
  • MVC3远程验证

        public class StudentModel
        {
            [Display(Name="学生编号")]
            public int StuId { set; get; }
    
            [Required(ErrorMessage="请输入学生姓名!")]
            [StringLength(10,ErrorMessage="姓名长度不能长于10!")]
            [Display(Name="学生姓名")]
            [Remote("ValirStuName","Student",HttpMethod="Post",ErrorMessage="学生姓名已经存在!")]
            public string StuName { set; get; }
    
            [Display(Name="学生Email")]
            [DataType(DataType.EmailAddress)]
            public string StuSex { set; get; }
            
            [Display(Name="班级ID")]
            public int Gid { set; get; }
    
            [Display(Name="学生描述")]
            public string StuDesc { set; get; }
        }

    Controller:

            /// <summary>
            /// 参数名称与Model中的名称一致
            /// </summary>
            /// <param name="StuName"></param>
            /// <returns></returns>
            public ActionResult ValirStuName(string StuName)
            {
                return Json(true);
                //return Json("你所填写的用户名,已经存在了!");//当返回不为true时,则默认认为验证失败及自定义的错误信息
                //return new JsonResult { Data=false,JsonRequestBehavior=JsonRequestBehavior.AllowGet };
            }
  • 相关阅读:
    石墨文档地址
    Emacs
    HDU
    田忌赛马(贪心
    poj 3040 Allowance (贪心
    cr545
    雕塑 ( 离散化,bfs-floodfill
    求m个不相交子段的和(复杂dp
    doing home work(dp-二进制法枚举
    非常可乐(多参数bfs模拟
  • 原文地址:https://www.cnblogs.com/myjacky/p/3318068.html
Copyright © 2011-2022 走看看