jquery ui datepicker and mvc view model type datetime

前端 未结 3 1264
攒了一身酷
攒了一身酷 2020-11-22 05:00

I am using jquery datepicker on my view model

Here is my view:

@Html.TextBoxFor(o => o.JobStartDate, new { id = \"dt1\", @class = \"input-block-le         


        
3条回答
  •  醉梦人生
    2020-11-22 05:30

    You will need to create a custom validator. You need to modify your property to take a string value instead like this

    public string JobStartDate {get; set; }
    

    You will then need to create your custom validator like this

    public class CheckDateAttribute : ValidationAttribute
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext) {
            // Validate your Date here
        }
    }
    

    After this you will just decorate your property as such -

    [CheckDate]
    public string JobStartDate {get; set;}
    

    Here is a good tutorial on custom validators

提交回复
热议问题