我正在尝试向网站添加管理员。在我的AccountsModels.cs上发现了问题
它只需要比较实现的数据,但我似乎会收到此错误。
我也有一个观点:
-Register.cshtml
-LogOn.cshtml
-ChangePasswordSuccess.cshtml
-ChangePassword.cshtml&当然是AccountController.cs。
有人知道解决方案吗?
这是代码:
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using System.Web.Security;
namespace Videoteek.Domain.Models
{
public class ChangePasswordModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Current password")]
public string OldPassword { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm new password")]
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
}
public class LogOnModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email address")]
public string Email { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
//****
[Required]
[Display(Name = "Security Question")]
public string PwdQuestion { get; set; }
[Required]
[Display(Name = "Security Answer")]
public string PwdAnswer { get; set; }
}
}
从您的代码看来,您想要将密码与确认密码进行比较。如果是这样,那么您的属性
Compare
是不正确的。它应该是
[CompareAttribute("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
您已经在代码中添加了所需的名称空间。您可以在此处了解更多信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句