MVC系列-6.注册页面
注册页面的实现
1.根据上回所介绍的Html Helper改造注册页view--Register.cshtml
1)在View的顶部需要添加一个强类型声明
@model MVCDemo.Models.Account
2)改造表单form标签
改为
@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class="form-horizontal"}))
{ }
3)改造lanel和input
参考资料:http://blog.csdn.net/pasic/article/details/7093802
改为
@Html.LabelFor(model => model.Email,new { @class = "col-sm-2 control-label" })
改为
@Html.TextBoxFor(model => model.Email, new { @class = "form-control" })
改为
@Html.LabelFor(model => model.PassWord)
改为
@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的代码 没有可省略本部分*@
}
转载于:https://www.cnblogs.com/lingr/p/5563463.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
