2017-05-17 14 views
0

C#MVCプログラムでjQuery DatePicker関数を使用していますが、「無効な日付」または今日のデフォルトの日付「17/05/2017」を示すエラーが無効です。ここでDatePickerからの無効な日付

は、同様に私のCreate.cshtmlの私のラベル/編集者としての私のjQueryの:

<div class="editor-label"> 
     @Html.LabelFor(model => model.DateOfReading) 
    </div> 
    <div class="editor-field"> 
     @Html.EditorFor(model => model.DateOfReading) 
     @Html.ValidationMessageFor(model => model.DateOfReading) 
    </div> 

<script> 
if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget: 
    jQuery(function ($) { //on document.ready 


     $('#DateOfReading').datepicker({ dateFormat: 'dd/mm/yy', maxDate: 0, defaultDate: 0 }).val(new Date().toLocaleDateString()); 
    }) 
} 
</script> 

は、ここに私のエンティティです:

[Required(ErrorMessage = "You must input a date")] 
    [Display(Name = "Date of Meter Reading")] 
    [DataType(DataType.Date)] 
    public DateTime DateOfReading { get; set; } 

答えて

2

は、あなたの方法に、この属性を追加します。

[DisplayFormat(DataFormatString = "{0:dd/MM/yy}", ApplyFormatInEditMode = true)] 
+0

私がメッセージ「価値 『17/05/2017』の検針の日のために有効ではありません。」を取得それでもなお – KOD459

+0

私は[Display(Name = "Meter Reading")の日付]は[Display(Name = "DateOfReading")]であるべきだと思います。 – tmutton

+0

jqueryプラグインはどのような価値がありますか?可能であれば、そこにconsole.logを入れてください。 – tmutton

関連する問題