Posting the selected dates to the controller

24 Mar 20221 minute to read

Post back is the action of posting the data back to the submitting page. In the following example, value for the DatePicker from the change event is sent through Ajax post to the controller.

When a parameter has [FromBody], Web API uses the Content-Type header to select a formatter. In this example, the content type is “application/json” and the request body is a JSON object. In the action method, you can pass a model as the parameter. The POST method determines how data is sent from the client via the form to the server.

@model EJ2_Core.Controllers.FormData

<ejs-datepicker ejs-for="" id="date" change="submit" width="200px"></ejs-datepicker>

    function submit(args) {
        var dateStr = args.value.toUTCString(); // Convert to UTC string
            type: "POST",
            url: '@Url.Action("ChangeData")',
            contentType: "application/json", // define content type
            dataType: "json",
            data: JSON.stringify({ 'date': dateStr}),   // pass data to controller