Aleksa
Aleksa

Reputation: 3124

Asp.net razor datetime validation

I have a following code in my page:

@Html.TextBoxFor(model => model.PublishingEndDate)
@Html.ValidationMessageFor(model => model.PublishingEndDate)

And input date format is dd.MM.yyyy HH:mm but validation fails. From where does the validation get the format, and can it be set globally in application?

Upvotes: 1

Views: 1638

Answers (1)

Oluwafemi
Oluwafemi

Reputation: 14899

You need to update your property validation attribute to include the format above like so:

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

Upvotes: 2

Related Questions