相关疑难解决方法(0)

ASP.NET MVC - 将模型值传递给数据注释参数

我想从我的模型中的一个属性传递一个值到我的数据注释来验证我的密码属性,但我不知道如何实现这一点.当我这样做时,我收到以下错误:

an attribute argument must be a constant expression typeof expression or array
Run Code Online (Sandbox Code Playgroud)

我的模特:

public class LoginModel
{
    public string Voornaam { get; set; }
    public string Achternaam { get; set; }
    public string Gebruikersnaam { get; set; }

    [Password(AttributeVoornaam = this.Voornaam, AttributeAchternaam = this.Achternaam, AttributeGebruikersnaam = this.Gebruikersnaam)]
    public string Wachtwoord { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

在我的数据注释中,我这样做:

public class PasswordAttribute : ValidationAttribute
{
    public string AttributeVoornaam { get; set; }
    public string AttributeAchternaam { get; set; }
    public string AttributeGebruikersnaam …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc model data-annotations

4
推荐指数
2
解决办法
7958
查看次数

标签 统计

asp.net-mvc ×1

data-annotations ×1

model ×1