2012-08-08 2 views
-2

http://thewayofcode.wordpress.com/2012/01/18/custom-unobtrusive-jquery-validation-with-data-annotations-in-mvc-3/MVC3 날짜 확인

나는 위의 링크 직장에서 샘플을 만들려고하지만 캔트는 올바른 얻을. 내가 뭘 잘못하고 있는지 모르겠다.

나는 DateGreaterThan 코드 다음에 모델 검증

[DataType(DataType.Date)] 
    [DisplayName("Start Date of Construction")] 
    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)] 
    public DateTime? StartDate { get; set; } 

[DataType(DataType.Date)] 
[DisplayNameAttribute("End Date of Construction")] 
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)] 
[DateGreaterThan("StartDate", "Estimated end date of construction must be greater than the start date of the construction")] 
public DateTime? EndDateOf { get; set; } 

을 복사. 버튼 클릭으로보기

@Html.EditorFor(model => model.StartDate) 
    @Html.EditorFor(model => model.EndDate) 
    @Html.ValidationMessageFor(model => model.StartDate) 
    @Html.ValidationMessageFor(model => model.EndDate) 

그러나 아무것도 화재에

, 사람이 어떤 light.It을 흘릴 수 있다면 정말 유용하거나 appreciated.Similarly를 얻기 위해 노력하고 심지어 다른 다른 방법이 될 것입니다 드롭 다운에서 값을 선택하고 텍스트 상자에 입력 한 값을 선택할 때 모델에서 유효성 확인 작업을 수행합니다. 최소한이 실행 얻을 경우 대신 [DisplayName("Start Date of Construction")]

+0

양식 데이터를 다시 게시하는 컨트롤러 코드를 볼 수 있습니까? – Tommy

+0

당신이 따르는 예제의 소스 코드는 [here] (https://github.com/vgheri/DateCustomValidationExample)에서 다운로드 할 수 있습니다. 다운로드하여 시도한 것과 비교해보십시오. 그러면 솔루션을 더 빨리 찾을 수있을 것이며 더 중요한 것은 문제를 스스로 해결할 수 있다는 것입니다. 나를 믿어 ! – Yasser

답변

1
  1. 는 참조 [Display(Name="End Date of Construction")]

를 사용해야합니다 [Display(Name="Start Date of Construction")]

  • 대신 [DisplayNameAttribute("End Date of Construction")]의 사용해야합니다. 데이터 주석 속성이 엉망이되어 웹에서 샘플을 찾습니다.

  • +0

    이것이 도움이 되었으면 알려주세요. 감사. –