Asp 网络核心控制器 URL 参数

Asp Net core Controller URL parameters

我有 Controller class 这样的:

namespace OptionsAPI.Controllers
{
    [Route("api/[controller]")]
    public class OptionsController : Controller
    {    
        HttpGet("{symbol}/{date}")]
        public IActionResult Chain(string symbol, string date)
        {
            DateTime quotedate = System.DateTime.Parse(date);
        }
    }
}

当我尝试像这样通过 URL 调用链函数时:

http://127.0.0.1:5000/api/options/Chain/symbol=SPX&date=2019-01-03T10:00:00

我收到这个错误:

FormatException: The string 'symbol=SPX&date=2019-01-03T10:00:00' was not recognized as a valid DateTime. There is an unknown word starting at index '0

似乎 "SPX" 和 "date" 被连接为一个 stringURL 的正确调用方式是什么?

动作中给定的路线模板

[HttpGet("{symbol}/{date}")]

连同控制器上的模板

[Route("api/[controller]")]

预计

http://127.0.0.1:5000/api/options/SPX/2019-01-03T10:00:00

但是被调用的URI

http://127.0.0.1:5000/api/options/Chain/symbol=SPX&date=2019-01-03T10:00:00

将URL中的Chain映射到symbol,其余映射到date,解析失败。

要获得所需的 URI,模板需要类似于

[Route("api/[controller]")]
public class OptionsController : Controller {

    //GET api/options/chain?symbol=SPX&date=2019-01-03T10:00:00
    [HttpGet("Chain")]
    public IActionResult Chain(string symbol, string date) {
        //...
    }
}

引用Routing to controller actions in ASP.NET Core

引用Routing in ASP.NET Core