我自己遇到了这个非常大的问题,经过数小时的尝试和失败,我得到了一个像你问的那样可行的解决方案。
首先,由于不可能仅在属性上使用活页夹,因此您必须实现完整的 ModelBinder。由于您不希望绑定所有单个属性,而只想绑定您关心的那个,因此您可以从 DefaultModelBinder 继承,然后绑定单个属性:
public class DateFiexedCultureModelBinder : DefaultModelBinder
{
    protected override void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, System.ComponentModel.PropertyDescriptor propertyDescriptor)
    {
        if (propertyDescriptor.PropertyType == typeof(DateTime?))
        {
            try
            {
                var model = bindingContext.Model;
                PropertyInfo property = model.GetType().GetProperty(propertyDescriptor.Name);
                var value = bindingContext.ValueProvider.GetValue(propertyDescriptor.Name);
                if (value != null)
                {
                    System.Globalization.CultureInfo cultureinfo = new System.Globalization.CultureInfo("it-CH");
                    var date = DateTime.Parse(value.AttemptedValue, cultureinfo);
                    property.SetValue(model, date, null);
                }
            }
            catch
            {
                //If something wrong, validation should take care
            }
        }
        else
        {
            base.BindProperty(controllerContext, bindingContext, propertyDescriptor);
        }
    }
}
在我的示例中,我正在使用固定文化解析日期,但您想要做的事情是可能的。您应该创建一个 CustomAttribute(如 DateTimeFormatAttribute)并将其放在您的属性上:
[DateTimeFormat("d.M.yyyy")]
public DateTime Birth { get; set,}
现在在 BindProperty 方法中,您可以使用 DateTimeFormatAttribute 查找属性,而不是查找 DateTime 属性,获取您在构造函数中指定的格式,然后使用 DateTime.ParseExact 解析日期
我希望这会有所帮助,我花了很长时间才提出这个解决方案。一旦我知道如何搜索它,实际上很容易获得这个解决方案:(