小编Nat*_*sea的帖子

ASP.Net Core MVC 日期时间参数

我想分享我如何在 .NET Core MVC 控制器中使用 DateTime 参数。我用它在我的解决方案中创建了日期范围过滤器功能。

不正确

[HttpGet, Route("dateRange/{start}/{end}")]
public IActionResult Get(DateTime start, DateTime end)
{
    //invalid values (e.g. /bogus/52) get converted to a valid DateTime value of 1/1/0001 00:00:00.001
    if (start != DateTime.MinValue && end != DateTime.MinValue)
    {            
        if (start < end)
        {
            return Json(_Repo.GetByDateRange(start, end));
        }
    }
    return BadRequest("Invalid Date Range");
}
Run Code Online (Sandbox Code Playgroud)

asp.net-core-mvc

2
推荐指数
1
解决办法
1663
查看次数

标签 统计

asp.net-core-mvc ×1