I want to pass the date as "dd-mm-yyyy"`
You have 3 options.
Option ISO8601
Don't pass it as "dd-mm-yyyy". Pass it instead in ISO8601 format (yyyy-MM-dd
). That is the correct way to serialize DateTime
s to string and also for then communicating that string representation between tiers. This format is a standard, widely used, unambiguous, and almost all frameworks that I am aware of have built in mechanisms for outputting DateTime
s to that format and parsing them from that format.
Displaying a DateTime
formatted as "dd-mm-yyyy" is a presentation layer concern and it should stay there and not "bleed" into the other application layers.
Option Formatters
Use custom code, like a Json Converte or an ActionFilterAttribute
, to read the incoming DateTime
.
Option String
Accept a string parameter instead and handle your own parsing inside the controller's method.
I honestly do not recommend the last 2 options. Instead use ISO8601: a standard, unambiguous, widely accepted means of communicating a DateTime
.