MVC 4 小功能总结

一、Model
[Required]    //表示必填
[Display(Name = "角色名称")]    //属性描述
[StringLength(10, ErrorMessage = "超出最大长度")]    //属性的最大长度
[StringLength(20, MinimumLength = 6, ErrorMessage = "密码为6~20位")]    //属性的最大长度和最小长度
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]  //设置属性的字符串格式(此设置在文本框的编辑状态下才有用)
[RegularExpression(@"^1[3|4|5|8][0-9]\d{8}$", ErrorMessage = "手机号格式不正确")]    //验证属性的正则表达式
public string RoleName { get; set; }

二、View

三、Controller
//弹出提示框到页面
var script = String.Format("<script>alert('密码重置成功!');location.href='{0}'</script>", Url.Action("List"));
return Content(script, "text/html");

 

posted @ 2013-12-30 13:54  塰杺茚佡  阅读(164)  评论(0编辑  收藏  举报