简体   繁体   中英

How to Make to Work End Date is Greater Than Begin Date Validation in ASP.NET MVC3

In View

    <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>

In Model

>

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

My Question, validation of end date and begin date required fields are working.but Greater Than validation is not working.actually i am using "foolproof" validations.please help me out.Thanks!!

The topic shows someone who created their own validaton attribute as well as the client rules for the validate plugin:

MVC custom validation: compare two dates

The answer to

Perform client side validation for custom attribute

shows how to get custom date validation working.

In a similar situation I used remote validation to check the minimum difference between the two dates, the minimum difference depended on the start date..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM