I have a situation in which I need to set a date and time to a hidden field via javascript. I must be able to catch this hidden field value as a parameter of my action in the server.
The problem is that I don't know what format to use to write the datetime in the hidden field. I googled a lot and didn't find a table explaining what datetime formats are compatible with the default model binding engine.
I've tried both iso datetime: "yyyy-mm-dd'T'HH:MM:ss" and iso utc datetime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'" with no success.
PS: I know ASP.NET MVC accounts for whether it's a GET or a POST while dealing with formats and cultures. My culture is PT-BR and it's a POST.
Take a look at the following blog post which explains very nicely what happens and how the default model binder works.
Actually the default model binder uses InvariantCulture for GET parameters and culture specific format for POST parameters. Because you are sending a POST request the ISO format is not recognized. In this case you could either change the culture of your application in the <globalization>
element of your web.config or write a custom model binder to override the default behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With