Tuesday, 15 February 2011

c# - DateTime Format In Model Binding -



c# - DateTime Format In Model Binding -

in web api project have next model:

public class modelclass { [required(errormessage = "date cannot empty", allowemptystrings = false)] [datatype(datatype.date, errormessage="date not in right date format")] public datetime date { get; set; } }

which beingness utilized in next action:

public httpresponsemessage submit([fromuri] modelclass model) { //do sth }

now if pass date localhost:3647/api/controller/submit?date=31/12/2015 modelstate validation fails datatype though changed globalization match date format of dd/mm/yyyy below:

<globalization culture="ms-my" uiculture="ms-my" />

i need help regarding asap please.

in asp.net mvc known query string parsed using invariantculture. post body parsed using thread culture. think allow create urls valid users.

look @ answer: http://stackoverflow.com/a/9977290/209727

or blog post: http://weblogs.asp.net/melvynharbour/mvc-modelbinder-and-localization

if need utilize format maybe can utilize string , parse within controller?

c# datetime asp.net-web-api cultureinfo asp.net-web-api2

No comments:

Post a Comment