mirror of
https://gitlab.com/buildfeed/BuildFeed.git
synced 2024-03-22 21:10:34 +08:00
18 lines
658 B
C#
18 lines
658 B
C#
|
using System;
|
|||
|
using System.Globalization;
|
|||
|
using System.Web.Mvc;
|
|||
|
|
|||
|
namespace BuildFeed
|
|||
|
{
|
|||
|
public class BuildDateTimeModelBinder : DefaultModelBinder
|
|||
|
{
|
|||
|
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
|
|||
|
{
|
|||
|
var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
|
|||
|
DateTime retValue;
|
|||
|
bool success = DateTime.TryParseExact(value.AttemptedValue, "yyMMdd-HHmm", CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out retValue);
|
|||
|
return success ? retValue as DateTime? : null as DateTime?;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|