0

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

tereško
  • 58,060
  • 25
  • 98
  • 150
  • If you use DateTime type, so your value will be like *02/02/2016 02:02:02.123*, right? So, as you can see, you have a space in your url, so it will not work. I might be mistaking, as you may use url encoding, but just wrote my suppose – Khazratbek Mar 14 '16 at 02:10

2 Answers2

0
protected void builtyLinkButton_click(object sender, EventArgs e)
{
    LinkButton lnk = (LinkButton)sender;
    GridViewRow row = (GridViewRow)lnk.NamingContainer;
    Label l1 = (Label)row.FindControl("Lbl_id");
    Response.Redirect("Loading_request.aspx?Id=" + (l1.Text) + "&Date=" +  (DateTime.Now.ToString()));
}
0

I just got it to work. The problem was in the View. I had to change

TimeRangeSelectedJavaScript = "document.location='Bokabord2?startingtime={0}';"

To:

TimeRangeSelectedJavaScript = "document.location='Bokabord2?startingtime=' + start;"

Now it sends a string with the selected date to the controller. There is very little information about the functions of DayPilotMonth on their website, hence why I couldn't find anything about it. Thanks all.