一次使用 "Remote" 和 "Compare" 注释时遇到错误

Facing error while using "Remote" and "Compare" annotation at a time

我正在使用远程验证来验证用户名是否已被使用,它工作正常。但是现在我需要添加 'compare' 数据注释来比较 passwordconfirmPassword 字段。但它给了我缺少装配的错误。当我删除库 System.Web.Mvc(用于 Remote)时,错误就消失了。 remotecompare 之间是否存在任何冲突,或者我遗漏了什么。

using System.Web.Mvc
using System.ComponentModel.DataAnnotaion

public partial class user
{
    [Remote("CheckExistingUsername","Home",ErrorMessage = "Email already exists!")]
    public string Username{get;set;}
    public string password {get;set;}

    [Compare("password",ErrorMessage="Un Matched")]
    public string confirmPassword {get;set;}
}

这样做,

[CompareAttribute("pass", ErrorMessage = "Unmatched")]

有关 CompareAttribute 的更多信息,请单击 here

尝试添加与命名空间的比较

[System.ComponentModel.DataAnnotations.Compare("pass",ErrorMessage = "unmatched")]

默认情况下它使用 System.Web.Mvc.CompareAttribute 的比较,这可能会导致问题