forum

Home / DeveloperSection / Forums / Send date from my front end (angular) to c# .net datetime (webapi)

Send date from my front end (angular) to c# .net datetime (webapi)

Lillian Martin 4104 21-Nov-2014

On my front-end I have a HTML input box where the user can enter a date. This adds data to my AngularJS modal and I then try to send it to the server as a JSON object when the user clicks save.

On the server I have used this which I think modifies the way dates are expected. All I know is that it allows AngularJS to nicely read the dates coming from the back-end.

     config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
        config.Formatters.Remove(config.Formatters.XmlFormatter);
        var json = config.Formatters.JsonFormatter;
        json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
        json.SerializerSettings.Converters.Add(new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-ddTHH:mmZ" });

Does anyone have any ideas how I can take a date entered into the input box in a format such as YYYY-MM-DD, modify in some way and then pass this to the server and have the server read it as a datetime?

The problem I have is that I am not sure how I can modify the YYYY-MM-DD date. When I try entering in a date like "2011-12-31" it does not get accepted by the server and the column that it should be entered into shows a null value for the date.


Updated on 21-Nov-2014

Can you answer this question?


Answer

1 Answers

Liked By