‘Compare’是’System.ComponentModel.DataAnnotations.CompareAttribute’和’System.Web.Mvc.CompareAttribute’之间的模糊引用。
我的AccountController中有这个错误。
找不到类型或命名空间名称’SelectListItem’(您是否缺少using指令或程序集引用?
显而易见的解决方法是using System.Web.Mvc;
添加using System.Web.Mvc;
但是,当我这样做时,我得到4个新错误
在两个不同的行:
找不到类型或命名空间名称’ErrorMessage’(您是否缺少using指令或程序集引用?)
在另外两个不同的行:
‘Compare’是’System.ComponentModel.DataAnnotations.CompareAttribute’和’System.Web.Mvc.CompareAttribute’之间的模糊引用。
为什么会发生这种情况,我该如何解决?
public class RegisterViewModel { [DataType(DataType.Password)] [Display(Name = "Confirm password")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] public string ConfirmPassword { get; set; } public IEnumerable DepotList { get; set; } }
ResetPasswordViewModel
public class ResetPasswordViewModel { [DataType(DataType.Password)] [Display(Name = "Confirm password")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] }
是啊。 这两个名称空间都具有相同function的属性。
根据msdn文档 , System.Web.Mvc.CompareAttribute
已过时,建议使用System.ComponentModel.DataAnnotations.CompareAttribute
因此要么使用包含命名空间的完全限定名称。
[DataType(DataType.Password)] [Display(Name = "Confirm password")] [System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] public string Name { get; set; }
或者,如果您不想在所有位置放置完全限定名称,则可以使用别名
using Compare = System.ComponentModel.DataAnnotations.CompareAttribute; public class ResetPasswordViewModel { [DataType(DataType.Password)] [Compare("Password", ErrorMessage = "The password and confirm password do not match.")] public string Password { set;get;} //Other properties as needed }
- 如何设置asp.net标识cookie到期时间
- CreateUserIdenityAsync返回自定义IdentityUser的“UserId not found”exception
- 如何注入UserManager和SignInManager
- 充分利用具有n(3)层架构的MVC Owin身份
- dependency injectionUserManager正在处理异步调用(ASP.NET CORE)
- 使用具有entity framework6的存储库模式更新记录
- 如何为Identity Framework设置entity framework模型以对抗现有数据库?
- 用于在MVC5中模拟ConfirmEmailAsync和其他UserManager方法的接口
- 我如何创建UserManager的实例