欢迎来到【一个大西瓜】的博客

不曾为梦想奋斗,拿什么去燃烧青春。有梦之人亦终将老去,但少年心气如昨。
太阳每一个时刻都同时是夕阳和朝阳,每天她沉入西边,意味着她同时从另一面土地升起。
扩大
缩小

MVC学习笔记

      1. CodeFirst生成数据库步骤
        webconfig配置
        <connectionStrings>
        <add name="AuthorDesignContext" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=AuthorDesign;Integrated Security=False;User Id=sa;Password=123456;MultipleActiveResultSets=True" />
        </connectionStrings>
        <configSections>
            <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
            <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
          </configSections>

        包管理器

        程序包管理器控制台输入Enable-migrations
        然后输入add-migration AddDatabase(AddDatabase是数据库名)
        最后输入Update-Database

         

      2. model字段验证
        /// <summary>
                /// 用户名
                /// </summary>
                [Required(ErrorMessage = "请输入用户名")]
                [StringLength(30, MinimumLength = 5, ErrorMessage = "请输入正确的用户名")]
                public string UserName { get; set; }
                /// <summary>
                /// 密码
                /// </summary>
                [Required(ErrorMessage = "请输入用密码")]
                [StringLength(30, MinimumLength = 5, ErrorMessage = "请输入正确的密码")]
                public string Password { get; set; }
                /// <summary>
                /// 验证码
                /// </summary>
                [Required(ErrorMessage = "请输入验证码")]
                [StringLength(6, MinimumLength = 6, ErrorMessage = "验证码错误")]
                public string ValidateCode { get; set; }
                /// <summary>
                /// 是否记住密码
                /// </summary>
                public bool IsRemind { get; set; }

        @model AuthorDesign.Web.Areas.Admin.Models.LoginModel
        //cshtml代码替换
        <input type="text" class="form-control" placeholder="用户名" />
        //替换
        @Html.TextBoxFor(m=>m.UserName,new { @class= "form-control",@placeholder="用户名" })
        
        //加入验证显示组件
        @Html.ValidationMessageFor(m => m.UserName);

 

posted on 2017-07-19 15:06  一个大西瓜咚咚咚  阅读(220)  评论(0编辑  收藏  举报

导航