MVC学习笔记
- 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
- 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);
作者:一个大西瓜
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!