Send DateTime instead of String to Controller through POST Request
Environment
Product | Progress® Telerik® UI DatePicker for ASP.NET MVC |
Product Version | 2018.2.620 |
Description
In my DatePicker project, I am using a POST request to send the value of the widget to the controller but the widget is sending a string. How can I receive a DateTime
value instead of a string value and what is the best approach to implement this functionality?
Solution
In order for the parameter to be received in the controller as a DateTime
value instead of a string value, use the Date.toUTCString
JavaScript method when you configure the POST request.
$.post('/MyController/MyMethod', {
start: start.toUTCString(),
end: end.toUTCString() },
function (result) {
callback(result);
});
The method in the controller looks similar to the what the following example demonstrates.
public ActionResult MyMethod(DateTime start, DateTime end){
...
}