views:

495

answers:

1

How can I modify the behavior of the autobinding in ASP.net MVC?

For instance, suppose I have a simple Employee object. One of the fields might be hiredate. When this field is bound to a textbox, it displays mm/dd/yyyy hh:mm:ss instead of just the date.

I know I can modify the view to add formatting, but I'm pretty sure I the autobinding can be modified, I'm just not sure how.

Edit

If possible, please include sample code.

+1  A: 

You have to create a Custom Model Binder, it's a bit of a pain though.

This fantastic post explains exactly what you're after. In it Scott Hanselman splits a date in several fields, but you could as well tweak it to just omit the time part:

http://www.hanselman.com/blog/SplittingDateTimeUnitTestingASPNETMVCCustomModelBinders.aspx

Hope that helped and the answer didn't come too late ;)

antonioh