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);
}