在下面的代码中,我想根据某些单选按钮的值为true或为某些文本框添加错误来添加RequireIfTrue属性。
public class Test{
public string BranchOption { get; set; }
public ClientAddressModel OldAddress { get; set; }
public ClientAddressModel NewAddress { get; set; }
}
public class ClientAddressModel
{
public string Country { get; set; }
public string County { get; set; }
public string City { get; set; }
public string Street { get; set; }
public string Number { get; set; }
public string Block { get; set; }
public string Stair { get; set; }
public string Floor { get; set; }
}
单击“新地址”单选按钮时,我要根据分支选项来验证“国家/地区”,“县”和“城市”属性,例如:
RequireIfTrue("BranchOption")
public string Country { get; set; }
问题在于BranchOption在测试模型中。
如果我这样说:
RequireIfTrue("BranchOption")
public ClientAddressModel NewAddress { get; set; }
正在验证NewAddressModel中的所有属性,而我不希望那样。
有没有办法做到这一点? 预先感谢。