asp.net – 在MVC视图上没有客户端密码匹配
发布时间:2020-12-16 07:35:40 所属栏目:asp.Net 来源:网络整理
导读:我有以下(删节)DTO注册新用户: [PropertiesMustMatch("Password","ConfirmPassword",ErrorMessage = "The password and confirmation password do not match.")]public class RegisterModel{ //..... [DataType(DataType.Password)] public string Password
我有以下(删节)DTO注册新用户:
[PropertiesMustMatch("Password","ConfirmPassword",ErrorMessage = "The password and confirmation password do not match.")] public class RegisterModel { //..... [DataType(DataType.Password)] public string Password { get; set; } [DataType(DataType.Password)] public string ConfirmPassword { get; set; } } 然后将其包装在View Model中: public class RegisterModelViewData: BaseViewData { public RegisterModel RegisterModel { get; set; } public int PasswordLength { get; set; } } 最后,在视图中,我有两个字段: <div class="editor-field"> <%= Html.PasswordFor(m => m.RegisterModel.Password) %> <%= Html.ValidationMessageFor(m => m.RegisterModel.Password) %> </div> <div class="editor-field"> <%= Html.PasswordFor(m => m.RegisterModel.ConfirmPassword) %> <%= Html.ValidationMessageFor(m => m.RegisterModel.ConfirmPassword) %> </div> 显然,如果密码不匹配,我应该得到客户端验证,没有帖子.我得到一个帖子,然后收到一条消息“帐户创建失败”,但没有关于密码不匹配的信息.为简洁起见,我在此处省略了密码proeprties中的Required和MininumLength属性,但它们似乎按预期运行并在客户端上进行验证. 解决方法
现在可以在ASP.MVC 3中使用,以防任何人仍然想知道
public string Password { get; set; } [Compare("Password",ErrorMessage = "Passwords must match")] public string ConfirmPassword { get; set; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET批量下载文件的方法
- 使用ASP.NET会话状态服务器(而不是InProc)的优点和缺点?
- asp.net – 带有Guid参数的ASMX webservice
- asp.net – 表单验证忽略默认文档
- ASP.NET MVC – 根据最后的帖子排序论坛帖子
- asp.net – 如何追踪过期的WIF fedauth cookies?
- asp.net – 如何使用Web服务返回接口或“复杂”值?
- asp.net-mvc – 如何在ASP.NET MVC中创建旋转广告块?
- asp.net-mvc-3 – 在生产环境中使用DropCreateDatabaseIfMo
- asp.net-core – .NET核心托管包
推荐文章
站长推荐
- asp.net-mvc – EF6模型和WebAPI 2.2 OData 4.0模
- asp.net-mvc – jQuery Ajax调用控制器
- asp.net – 从ActionFilterAttribute返回自定义H
- ASP.NET MVC4异步聊天室的示例代码
- asp.net-mvc – 我可以从服务器端的持票令牌中检
- 当通过ASP.NET成员资格检查用户角色时,Semaphore
- asp.net-mvc – 使用SaveAs对话框下载Rotativa
- asp.net-mvc-4 – 什么文件夹应该把我的扩展方法
- asp.net – 检查控制启动的AJAX请求
- asp.net-mvc – 开始学习ASP.NET MVC专家级的最佳
热点阅读