不,好像不是虫子。您可以在此处获得更多详细信息:
MVC DateTime binding with incorrect date format
我一直在使用下面的ModelBinder来解决这个问题。
public class CurrentCultureDateTimeBinder : IModelBinder
{
private const string PARSE_ERROR = "\"{0}\" is not a valid date";
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
if (valueProviderResult == null) return null;
var date = bindingContext.ValueProvider.GetValue(bindingContext.ModelName).AttemptedValue;
if (String.IsNullOrEmpty(date))
return null;
bindingContext.ModelState.SetModelValue(bindingContext.ModelName, bindingContext.ValueProvider.GetValue(bindingContext.ModelName));
try
{
return DateTime.Parse(date);
}
catch (Exception)
{
bindingContext.ModelState.AddModelError(bindingContext.ModelName, String.Format(PARSE_ERROR, bindingContext.ModelName));
return null;
}
}
}
希望它有帮助。