将验证添加到共享类

时间:2017-01-09 17:13:51

标签: c# .net asp.net-mvc-4

我有一个共享的简单类。我有DataAnnotations来显示必填字段

public class Address
{
    [Required]
    public string Contact { get; set; }

    [Required]
    public string Address1 { get; set; }

    public string Address2 { get; set; }

    public string Company{ get; set; }
}

在使用此课程的一个实例中,我需要使公司成为必需。只在需要时才需要公司的最佳方式是什么。

Address对象正在其他类中使用,例如Order,Account等。

0 个答案:

没有答案