Last active
October 22, 2015 15:46
-
-
Save halityurttas/11dac02e75a063cb5dea to your computer and use it in GitHub Desktop.
ASP.Net MVC de türkçe tarih okumak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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