How to specify date format for model binding?

别来无恙 提交于 2019-11-30 17:18:37
Steve Greatrex

This blog post explains how you can specify a particular date format to be used by the MVC model binder.

You will need to create a custom model binder implementation that is aware of the date format, then associate that with the DateTime type in your Global.asax.cs:

protected void Application_Start()
{
    //...
    var binder = new DateTimeModelBinder(GetCustomDateFormat());
    ModelBinders.Binders.Add(typeof(DateTime), binder);
}
Manaf Abu.Rous

You might find the answer to your question here

Custom DateTime model binder in Asp.net MVC

Also Scott Hanselman has talked about a DateTime custom model binder here

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

Although he's using the binder to split the date & time you might his post useful when creating your custom model binder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!