不了解.net核心[FromQuery]或未正确实施路由匹配

时间:2019-06-13 18:29:01

标签: .net-core odata asp.net-core-webapi

我有以下要求:

 https://localhost:44341/odata/Events/?StartDate=2019-05-26T04:00:00.000Z&EndDate=2019-07-07T04:00:00.000Z

在控制器中,我有以下内容:

 [EnableQuery]
    public IActionResult Get([FromQuery]string StartDate, [FromQuery]string EndDate)
    {
        DateTime sDate = Convert.ToDateTime(StartDate);
        DateTime eDate = Convert.ToDateTime(EndDate);
        return Ok(_dbContext.Events.Select(c => c.StartTime >= sDate && c.EndTime <= eDate));
    }


    [EnableQuery]
    public IActionResult Get()
    {
        return Ok(_dbContext.Events);
    }

我希望请求将第一个Get与开始和结束参数一起使用。但是,它始终使用默认值。我不确定自己做错了什么。

任何启发都会受到赞赏。

谢谢

这是调试的一些输出:

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:44341/odata/Events/?StartDate=2019-05-26T04:00:00.000Z&EndDate=2019-07-07T04:00:00.000Z
Microsoft.AspNetCore.Cors.Infrastructure.CorsService:Information: CORS policy execution successful.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Route matched with {action = "Get", controller = "Events"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Get() on controller DevOdata.Controllers.EventsController (DevOdata).

1 个答案:

答案 0 :(得分:0)

似乎存在路由问题:

https://github.com/OData/WebApi/issues/1794

希望搜索神们昨天已将此链接显示在表面。今天在我的搜索结果中排名第三。