2011-11-08 5 views
1

나는 원격 검증 속성이 조직에기구라는 모델이 있습니다ASP.NET MVC 3 모델 검증

[Required(ErrorMessage = "The organisation name is required")] 
    [Remote("NameCheck", "Manage", "Organisations", ErrorMessage="That organisation  already exists")] 
    public string Name { get; set; } 

이 조직 누군가의 이름이 이미 존재하지 않는 추가되었는지 확인을 . 그럴 경우 오류 메시지가 나타납니다.

강력한 형식의보기를 사용하여 조직의 "편집"보기를 렌더링하고 있습니다. 누군가 편집 중이기 때문에 조직이 존재하기 때문에 원격 인증이 실행되기를 원하지 않습니다.

이것을 달성 할 방법이 있습니까? 기본적으로 조직을 편집 할 때 어떤 방식 으로든 원격 유효성 검사를 끄고 조직을 만들 때이를 켜십시오.

+4

사용자가 영국 영어를 원하면 조직이됩니다. 그들이 미국 영어를 기대한다면 조직이 될 것입니다. 일관된 철자를 통해 나는 그것이 이전의 것이라고 생각합니다. –

+0

John Hartsock, Jared Peless,이 기사는 http://english.stackexchange.com/에서 유용 할 수 있지만 StackOverflow와 같은 프로그래밍 관련 Q & A 사이트에서는별로 도움이되지 않을 수 있습니다. –

답변

3
public class BaseOrganizationModel { 
    public int ID {get; set;} 
} 

public class UpdateOrganizationModel : BaseOrganizationModel { 
    [Required(ErrorMessage = "The organisation name is required")] 
    public string Name { get; set; } 

} 

public class InsertOrganizationModel : BaseOrganizationModel { 
    [Required(ErrorMessage = "The organisation name is required")] 
    [Remote("NameCheck", "Manage", "Organisations", ErrorMessage="That organisation  already exists")] 
    public string Name { get; set; } 

} 
+0

감사합니다. – Paul

4

당신은/ 두 뷰의 다른보기 모델을 사용해야한다 수 있습니다. 예를 들어, CreateOrganizationViewModel과 UpdateOrganizationViewModel을 가질 수 있습니다. 첫 번째 뷰 모델에서는 Name 속성이 원격 특성으로 꾸며졌지만 두 번째 뷰 모델에서는 그렇지 않습니다.

+0

감사합니다. 좋은 대답. – Paul