2012-08-08 114 views
-2

http://thewayofcode.wordpress.com/2012/01/18/custom-unobtrusive-jquery-validation-with-data-annotations-in-mvc-3/MVC3日期验证

我试图从上面的链接工作,但不能得到它正确的示例。我不确定我做错了什么?

我复制的模型验证

[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; } 

其次DateGreaterThan代码。

在查看

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

但没有火灾的按钮点击

,如果有人能提供一些线索light.It将是非常有益的,甚至这样做是appreciated.Similarly试图获得的任何其他不同的方式在下拉列表中选择一个值并在文本框中输入值时,从Model进行验证工作。

+0

我们可以看到您的控制器代码在哪里发布表单数据? – Tommy 2012-08-08 21:49:19

+0

您正在关注的示例的源代码可以从[here](https://github.com/vgheri/DateCustomValidationExample)下载。下载它,并与您尝试过的内容进行比较,这样您就可以更快地找到解决方案,更重要的是,您将很乐意自己找出问题所在。相信我 ! – Yasser 2012-08-09 05:25:39

回答

1
  1. 而不是[DisplayName("Start Date of Construction")]应使用而不是[DisplayNameAttribute("End Date of Construction")][Display(Name="Start Date of Construction")]
  2. 应该使用[Display(Name="End Date of Construction")]

看看你至少该运行。您的数据注释属性会混乱,只需在Web上查找示例即可。

+0

请让我知道这是否有任何帮助!谢谢。 – 2013-02-05 23:19:18