我传递的日期到我的服务器不变文化,格式如下MVC 1参数绑定
'mm/dd/yy'
参数在MVC绑定失败来解析这个日期和参数返回null。这很有可能是因为IIS运行在使用英语文化的机器上('dd/mm/yy'工作正常)。
我想重写所有日期的解析我的服务器使用固定区域性像等等......
Convert.ChangeType('12/31/11', typeof(DateTime), CultureInfo.InvariantCulture);
即使日期是另一个对象的一部分......
public class MyObj
{
public DateTime Date { get; set; }
}
我的控制器方法是这样的....
public ActionResult DoSomethingImportant(MyObj obj)
{
// use the really important date here
DoSomethingWithTheDate(obj.Date);
}
日期被发送为Json数据所以....
myobj.Date = '12/31/11'
我试过在Global.asax
binderDictionary.Add(typeof(DateTime), new DateTimeModelBinder());
这不起作用增加IModelBinder到binderDictionary的实现,而且也不
ModelBinders.Binders.Add(typeof(DateTime), new DataTimeModelBinder());
这似乎是一些人会想要一直做的。我看不出为什么要在服务器上的当前文化中解析日期等。客户端将不得不找出服务器的文化,只是为了格式化日期服务器将能够解析.....
任何帮助表示赞赏!
的问题是,我的自定义模型绑定器永远不会被调用 – Gaz 2011-04-13 08:00:23