MVC系列-6.注册页面
注冊頁面的實現
1.根據上回所介紹的Html Helper改造注冊頁view--Register.cshtml
1)在View的頂部需要添加一個強類型聲明
@model MVCDemo.Models.Account
2)改造表單form標簽
<form class="form-horizontal"> </form>
改為
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class="form-horizontal"}))
??????? {??? }
3)改造lanel和input
參考資料:http://blog.csdn.net/pasic/article/details/7093802
<label for="inputEmail3" class="col-sm-2 control-label">郵箱</label>
改為
@Html.LabelFor(model => model.Email,new { @class = "col-sm-2 control-label" })
<input type="email" class="form-control" id="inputEmail3" placeholder="輸入郵箱">
改為
@Html.TextBoxFor(model => model.Email, new { @class = "form-control" })
<label for="inputPassword3" class="col-sm-2 control-label">密碼</label>
改為
@Html.LabelFor(model => model.PassWord)
<input type="password" class="form-control" id="inputPassword3" placeholder="輸入密碼">
改為
@Html.PasswordFor(model => model.PassWord, new { @class ="form-control" })
地址改造方法同郵箱
代密碼如下:
2.在AccountController下新增一個[HttpPost]Register方法
3.增加客戶端驗證,兩次密碼是否一致
1)修改表單屬性
增加form屬性
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class="form-horizontal",@onsubmit = "return IsValid()" }))
增加表單提交驗證屬性:@onsubmit = "return IsValid()"
2) 創建JavaScript 驗證文件
在Script文件下,新建JavaScript文件,命名為“Validations.js”
3) 創建驗證函數
在“Validations.js”文件中創建驗證函數:
4)View 中添加 Validations.js文件引用:
@section HeaderSection{
@*注釋:這里放引入js css的代碼? 沒有可省略本部分*@
<link href="~/Content/Site.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/Validations.js"></script>
}
轉載于:https://www.cnblogs.com/lingr/p/5563463.html
總結
以上是生活随笔為你收集整理的MVC系列-6.注册页面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android深度探索读书笔记 第六章
- 下一篇: MVC5中EF6 Code First启