gpt4 book ai didi

c# - 无法找到类型或命名空间比较(您是否缺少 using 指令或程序集引用?)

转载 作者:太空狗 更新时间:2023-10-29 22:22:51 25 4
gpt4 key购买 nike

我正在尝试向我的站点添加管理员。在我的 AccountsModels.cs 上发现问题

它只需要比较实现的数据,但我似乎遇到了这个错误。

I also have a view with:
-Register.cshtml
-LogOn.cshtml
-ChangePasswordSuccess.cshtml
-ChangePassword.cshtml

& an AccountController.cs of course..

有人知道解决方案吗?

代码如下:

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.")]

您已经在代码中添加了所需的命名空间。您可以阅读更多相关信息 here .

关于c# - 无法找到类型或命名空间比较(您是否缺少 using 指令或程序集引用?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18288719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com