In a previous question that I asked on StackOverflow, I mentioned that I was able to retrieve my values successfully as the object was no longer null. The object contains a DateTime property named CreatedOn, which I am sending from JavaScript using new Date(). Instead of retrieving DateTime.Now() from code-behind, I have a specific reason for sending the date from HTML.
However, when I debug and reach the controller method, I noticed that the value of CreatedOn is always set to DateTime.MinValue = 01/01/0001 12:00:00 AM.
I attempted to change the format of my JavaScript value to "yyyyMMddT000000" in hopes that it would be automatically parsed, but that did not work as expected.
Is there a way for me to send a value that can be parsed by the Web API2 controller automatically?
<script>
$("#btnTest").on("click", function () {
var searchCriteria = {};
searchCriteria.ID = 0;
searchCriteria.Name = "";
//1. First tried option
//searchCriteria.CreatedOn = new Date();
//2. Second tried option. Test
searchCriteria.CreatedOn = "20170324T000000";
var url = "http://localhost:8080/api/products"
$.getJSON(url, searchCriteria).done(processResponse);
});
function processResponse(response){
}
</script>