Skip to content

Instantly share code, notes, and snippets.

@halityurttas
Last active October 22, 2015 15:46
Show Gist options
  • Save halityurttas/11dac02e75a063cb5dea to your computer and use it in GitHub Desktop.
Save halityurttas/11dac02e75a063cb5dea to your computer and use it in GitHub Desktop.
ASP.Net MVC de türkçe tarih okumak
public class DatetimeBinder: IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
string data = "";
if (controllerContext.Controller.ValidateRequest && bindingContext.ModelMetadata.RequestValidationEnabled)
{
data = controllerContext.HttpContext.Request.Params[bindingContext.ModelName];
}
else
{
data = divalueProvider.GetValue(bindingContext.ModelName, true).AttemptedValue;
}
DateTime dt = new DateTime();
if (DateTime.TryParse(data, CultureInfo.GetCultureInfo("tr-TR"), DateTimeStyles.None, out dt))
{
return dt;
}
else
{
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment