0

Is it possible to set a minimum and maximum selectable date/datetime for Html.EditorFor?

@Html.EditorFor(model => model.Date)

If yes, how?

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
FS'Wæhre
  • 196
  • 2
  • 16
  • 2
    Does this answer your question? [Data-attributes with html editor for mvc](https://stackoverflow.com/questions/18177335/data-attributes-with-html-editor-for-mvc) – freedomn-m May 19 '21 at 08:48
  • 1
    Depends on your version of MVC. It seems to change each version, but this has been an option for many years, so likely what you need: https://stackoverflow.com/a/22556424/2181514 – freedomn-m May 19 '21 at 08:49

1 Answers1

0

I looked into the suggestions in comments and it worked (kindof) by using the [DataType(DataType.DateTime)] attribute on the model property in combination with

@Html.EditorFor(model => model.Date, new { htmlAttributes = new { @min= "2021-05-19" } })

However that gave me issues with formatting and submitting my form.. i ended up handling the date validation in the controller..

FS'Wæhre
  • 196
  • 2
  • 16