簡體   English   中英

無法從查詢字符串獲取正確的DateTime

[英]Can't get a correct DateTime from querystring

我是C#和MVC編碼的新手。 我正在制作預訂應用程序,並且正在使用DayPilotMonth作為日歷。 我在視圖中使用以下代碼:

    @Html.DayPilotMonth("dpm", new DayPilotMonthConfig
{
BackendUrl = Url.Content("~/Home/Backend"),
TimeRangeSelectedHandling = DayPilot.Web.Mvc.Events.Month.TimeRangeSelectedHandlingType.JavaScript,
TimeRangeSelectedJavaScript = "document.location='Bokabord2?startingtime={0}';"})

根據DayPilot上的某個人的說法,TimeRangeSelectedJavaScript中的{0}以DateTime格式給出了單擊日期。

現在,當我嘗試在控制器中使用“啟動時間”時,將無法進行任何操作。 似乎值始終為空,我找不到轉換它的方法。 這是我一直在嘗試使用的代碼:

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

    }

當我運行該應用程序時,錯誤消息總是顯示在Convert.ToDateTime行上,並顯示有關無法轉換為DateTime的字符串的信息。

在此先感謝菲利普

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

我剛開始工作。 問題出在視圖中。 我不得不改變

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

至:

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

現在,它將帶有選定日期的字符串發送到控制器。 在他們的網站上,關於DayPilotMonth的功能的信息很少,因此為什么我找不到任何信息。 謝謝大家

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM