2014-01-30 1 views
1

아래에는 세 가지 카테고리가 있습니다.Bools로 데이터 주석

적어도 하나의 부울이 범주별로 선택되도록하려면 유효성 검사를 어떻게 구성합니까?

// 장애인

[Display(Name = "Learning Disabilities")] 
    public bool LD { get; set; } 

    [Display(Name = "Developmental Disabilities")] 
    public bool DD { get; set; } 

    [Display(Name = "AD/HD")] 
    public bool ADHD { get; set; } 

    [Display(Name = "Autism")] 
    public bool Autism { get; set; } 

// 연령 그룹

[Display(Name = "Child")] 
    public bool child { get; set; } 

    [Display(Name = "Youth")] 
    public bool youth { get; set; } 

    [Display(Name = "Adult")] 
    public bool adult { get; set; } 

// 전략 유형

[Display(Name = "Academic")] 
    public bool academic { get; set; } 

    [Display(Name = "Behaviour")] 
    public bool behaviour { get; set; } 

    [Display(Name = "Communication")] 
    public bool communication { get; set; } 

    [Display(Name = "Social")] 
    public bool social { get; set; } 
+0

가능한 중복 :

public enum Age { [Display(Name="Child") Child, [Display(Name="Youth") Youth, [Display(Name="Adult") Adult } 

는 다음과 같이 모델의 속성이 있습니다. 유효성 검사를 설정하여 모델의 bool 값에 따라 두 필드 중 하나가 필요합니까?] (http://stackoverflow.com/questions/11143151/asp-net-mvc3-how-to-set-validation-to-require- 1 대 2 필드 (bo-on-on-bo) – MarcinJuraszek

답변

4

다른 모델을 사용하는 것이 좋습니다. 당신이하려고하는 것이 범주 당 하나 이상의 선택을 시행한다면, 그것들을 함께 그룹화하고 필수 속성을 사용하는 것이 더 낫습니다. [ASP.NET MVC3의

[Required] 
public Age MyAge { get; set; }