0
У меня есть следующие пользовательские ModelBinder для DateTime:Пользовательские ModelBinder не работает для Nullable типов
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
ValueProviderResult value = null;
try
{
value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
return DateTime.ParseExact(value.AttemptedValue, _customFormat, CultureInfo.InvariantCulture);
}
catch (Exception)
{
// If there is a place where DateTime got used which "Bypassed" our EditorTemplate, it means the format will be the default format.
// So let's allow the Model Binder to at least try to Parse the date with the default format.
return DateTime.Parse(value.AttemptedValue);
}
}
Если я указать аргумент в моем действии как обнуляемого DateTime (DateTime? dob
), то ModelBinder не срабатывает.
Как я могу заставить ModelBinder работать с нулевым значением DateTime?
Я просто понял свою ошибку, и собирался отправить ответ на свой вопрос. благодаря –