4

Update I give the model .

[DataType(DataType.Date)]
[Required(ErrorMessage = "Введите значение начальной даты")]
public DateTime House1 { get; set; }

When I use @ Html.EditorFor (model => model.House1) in View.I have following marking

 <input class="text-box single-line" data-val="true" data-val-date="The 
 field  StartDate must be a date." data-val-required="Введите значение"   
 id="StartDate" name="StartDate" type="date" value="29.06.2015"> 

But data not display in a field.display means not pulled from the model in input(@ Html.EditorFor (model => model.House1))

6
  • Do you mean m => m.House1 or m => m.StartDate? And why do you mean it does not display - the html you have shown has a value of "29.06.2015" Commented Jul 22, 2015 at 7:48
  • sorry ,I wrote incorrectly,i have the value="29.06.2015"(in inspector),but it is not displayed to the user Commented Jul 22, 2015 at 7:51
  • That's because your format for the date is incorrect. You need to show the model property including its data annotation attributes. Commented Jul 22, 2015 at 8:07
  • which data annotation attributes?You can show how to write? Commented Jul 22, 2015 at 8:15
  • You need to show what you have written (show your model) and I will show you how to correct it Commented Jul 22, 2015 at 8:21

1 Answer 1

6

The specification for the HTML-5 datepicker requires that the format be yyyy-MM-dd, so you need to modify your property to add the DisplayFormatAttribute

[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public DateTime House1 { get; set; }

However keep in mind that there is only limited support for the HTML-5 datepicker and its not even implemented in FireFox. I recommend you consider using a jquery plugin instead

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.