0
votes

Javascript code

function setDate(id) {

        debugger;
        $('#doctorId').val(id.name);
        $('#hhduration').val(id.id);
        var datesArray = [];
        var d = new Date();
        var startdate = d.toLocaleString();
        var ed = new Date();
        ed.setDate(d.getDate() + 12);
        var Enddate = ed.toLocaleString();
        var doctorId = id.name;

        $.ajax({
            type: "POST",
            url: '@Url.Action("GetAvailabledates", "Home")',
            data: { startdate: startdate, enddate: Enddate, doctorid: doctorId },
            datatype: "json",
            async: false
        }).done(function (data) {

            try {
                if (data.length > 0) {
                    debugger;
                    datesArray = data;
                }



            }
            catch (e) {

            }
        });

MVC Controller method

        [HttpPost]
        public ActionResult GetAvailabledates(DateTime startdate,DateTime? enddate,string doctorid)
        {
            int[] dates = null;
            using (DepartmentOperations dos = new DepartmentOperations())
            {
                 dates = dos.GetAvailabledates(startdate, enddate, doctorid);
            }
            return Json(dates, JsonRequestBehavior.AllowGet);
        }
1
Use browser Developer Console (Network tab) to inspect values sent by browser. - Dmitry

1 Answers

0
votes

Use Json Signify make Enddate not null if you do not pass date then it will pass as '0001-01-01 00:00:00'

one more thing if you want to set nullable thing then it should be last in parameter of the controller

https://cmatskas.com/asp-net-mvc-webapi-optional-parameters/