I'm pretty new to C# and MVC coding. I'm making a booking application and I'm using DayPilotMonth for a calendar. I'm using the following code in my view:
@Html.DayPilotMonth("dpm", new DayPilotMonthConfig
{
BackendUrl = Url.Content("~/Home/Backend"),
TimeRangeSelectedHandling = DayPilot.Web.Mvc.Events.Month.TimeRangeSelectedHandlingType.JavaScript,
TimeRangeSelectedJavaScript = "document.location='Bokabord2?startingtime={0}';"})
According to someone on DayPilot the {0} in TimeRangeSelectedJavaScript gives the clicked date in DateTime format.
Now when I'm trying to use the 'startingtime' in my controller nothing works. It seems like the value is always null and I can't find a way to convert it. This is the code I have been trying to use:
public ActionResult Bokabord2(DateTime? startingtime)
{
DateTime startingTime;
if (Session["InloggatId"] != null)
{
if (Request.QueryString["startingtime"] != null)
{
startingTime = Convert.ToDateTime(Request.QueryString["startingtime"]);
ViewBag.Message2 = startingtime;
}
else
{
ViewBag.Message2 = "Error";
}
return View();
}
else
{
return RedirectToAction("Login", "Account");
}
}
When I run the application the error message always shows up at the Convert.ToDateTime line and says something about string not able to convert to DateTime.
Thanks in advance Regards Philip