I'm trying to bind a form to a model parameter in a controller. The model contains a DateTime field and I'd like that to be bound when the form is submitted. The form field expects the date to be input in a non-standard format (which I can't change - for various reasons).
The controller action is:
public ActionResult Registration_Post(RegistrationDetails model)
I only need to custom bind a (DateTime) DateOfBirth property in the RegistrationDetails class. All the rest of the properties work with the default binding.
I don't want to override the DateTime binding for the whole app - just for this single action (or, if easier, controller).
Any idea how I can do this? I tried using the ModelBinder attribute on the action, as in:
public ActionResult Registration_Post([ModelBinder(typeof(CustomDateTimeBinder)]RegistrationDetails model)
However, it appears that I need to create a custom binder for the whole RegistrationDetails class, which seems like overkill.
Also, I'd prefer not to put the custom format on the model property, as the class is used elsewhere, so I be polluting the class.
I'm using MVC4.
Can anyone tell me the best way of handing this?