0

I am sending DateTime values from form to a controller. The field in the model is a DateTime?. When sending the value using MM/dd/yyyy the binding works correct and the value is available in the controller.

When changing the dateformat to dd/MM/yyyy the model binding is not working and the value is null when received inside the controller.

Any tips would be really helpfull here.

itminus
  • 23,772
  • 2
  • 53
  • 88
gwinnem
  • 66
  • 4
  • 6
    Consider editing your question and adding the relevant code – Cleptus Jun 06 '19 at 12:36
  • 1
    An option could be send as a string and then Convert.ToDateTime in the format you expect it, there are issues with Locale, browser locale, system locale too. – Rav Jun 06 '19 at 12:40
  • Possible duplicate of https://stackoverflow.com/questions/528545/mvc-datetime-binding-with-incorrect-date-format – akg179 Jun 06 '19 at 12:47
  • @bradbury9 the question is general and does not apply to specific code. It applies to all code when trying to send a date to a mvc controller in format dd/MM/yyyy so please do not ask for code examples when it is not relevant. – gwinnem Jun 08 '19 at 04:02
  • @Rav tnxs for the reply, i have already thought of that and tried it so i know that will work but i raises some concerns for me when i have to deal with hacks like that instead of understanding why it happends only for that specific date format. – gwinnem Jun 08 '19 at 04:02
  • @akg tnxs for the link. I forgot to specify that im running asp net core. and the thread you are linking to references older versions, Some of them with hacks which i do not like. I will have to dig deeper into how the modelbinder works and write a custom date model binder to solve this. – gwinnem Jun 08 '19 at 04:04

0 Answers0