how to fix 'The field must be a date' on a datetime property in mvc

前端 未结 13 1230
逝去的感伤
逝去的感伤 2020-12-29 06:59

I need to capture date and time both for my model property. In my model class I have the following

[Required]
[DataType(DataType.DateTime)]
public DateTime?          


        
13条回答
  •  长情又很酷
    2020-12-29 07:07

    In my case in my Model I had :

    [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}", ApplyFormatInEditMode = true)].
    

    In my view in my script, I had:

        $(function () {
                    $('.datepicker').datepicker({
                        changeMonth: true,
                        changeYear: true,
                        format: "dd MMM yyyy"
                    });
            });

    When I changed my script's format to format: dd M yyyy - it worked.

提交回复
热议问题