How do I pass a datetime value as a URI parameter in asp.net mvc?

前端 未结 10 1104
孤城傲影
孤城傲影 2020-12-04 18:58

I need to have an action parameter that has a datetime value? Is there a standard way to do this? I need to have something like:

mysite/Controller/Action/2         


        
10条回答
  •  旧时难觅i
    2020-12-04 19:18

    Try to use toISOString(). It returns string in ISO8601 format.

    from javascript

    $.get('/example/doGet?date=' + new Date().toISOString(), function (result) {
        console.log(result);
    });
    

    from c#

    [HttpGet]
    public JsonResult DoGet(DateTime date)
    {
        return Json(date.ToString(), JsonRequestBehavior.AllowGet);
    }
    

提交回复
热议问题