2012-01-26 49 views
0

在查看如何对工作结束日期大于开始日期验证在ASP.NET MVC3

<td class="SrcFld"> 
     <div> 
     @Html.TextBox("BeginDate", Model.BeginDate)&nbsp; 
     @Html.RequiredFieldFor(model => model.BeginDate) 
     @Html.ValidationMessageFor(model => model.BeginDate) 
     To &nbsp; @Html.TextBox("EndDate", Model.EndDate) 
     @Html.RequiredFieldFor(model => model.EndDate) 
     @Html.ValidationMessageFor(model => model.EndDate) 
     </div> 
    </td> 

在型号

>

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.ComponentModel; 
using System.ComponentModel.DataAnnotations; 
using Foolproof; 

namespace HPAI.HPA.Web.Models 
{ 
    public class UnEmploymentInputs : UserInputs 
    { 
     [Required] 
     public DateTime? BeginDate { get; set; } 
     [Required] 
     [GreaterThan("BeginDate", ErrorMessage = "End Date Should be Greater Than Begin Date.")] 
     public DateTime? EndDate { get; set; } 
     public decimal? NonEscrowTax { get; set; } 
     public decimal? NonEscrowInsurance { get; set; } 
     public bool? IsExtension { get; set; } 
     public bool? IsIncomeCircumstance { get; set; } 
    } 

我的问题,的 验证结束日期和开始日期必填字段working.but大于验证不工作。实际上,我正在使用“万无一失”验证。请帮助我out.Thanks!

回答

0

的主题说明有人谁创造了他们自己validaton属性以及为验证插件,客户端的规则:

MVC custom validation: compare two dates

+0

嗨,其实我使用万无一失validatiors。但它不是... ...! – user1169594

+0

你是否遵循“万无一失”@ http://foolproof.codeplex.com/的指导?你是否包含了所有需要的验证脚本?没有脚本,客户端验证将不会发生。他们的示例和您的代码之间唯一的区别是他们的代码不使用可空的DateTime。 –

相关问题