Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用可选参数创建路由时出现问题_C#_.net_Rest_.net Core - Fatal编程技术网

C# 使用可选参数创建路由时出现问题

C# 使用可选参数创建路由时出现问题,c#,.net,rest,.net-core,C#,.net,Rest,.net Core,我有以下的装饰师: [HttpGet("{parameterType}/{parameter}/{product: int?}")] 函数标题如下所示: public IActionResult GetServices(int parameterType, string parameter, int? product= null) 我只想选择性地传递产品,但它给了我以下错误: The constraint entry 'product' - ' int' on the route 'api/

我有以下的装饰师:

[HttpGet("{parameterType}/{parameter}/{product: int?}")]
函数标题如下所示:

public IActionResult GetServices(int parameterType, string parameter, int? product= null)
我只想选择性地传递
产品
,但它给了我以下错误:

The constraint entry 'product' - ' int' on the route 'api/Service/{parameterType}/{parameter}/{product: int?}' could not be resolved by the constraint resolver of type 'DefaultInlineConstraintResolver'.

如何引导它?

您不需要指定路线约束。而不是

[HttpGet("{parameterType}/{parameter}/{product: int?}")]`
使用


您不需要指定管线约束。而不是

[HttpGet("{parameterType}/{parameter}/{product: int?}")]`
使用


只是远程:int?从…起decorator@S.Petrosov如果我从装饰器中删除它,那么它将是必需的参数。(我大摇大摆地测试)只是远程:int?从…起decorator@S.Petrosov如果我从装饰器中删除它,那么它将是必需的参数。(我大摇大摆地测试它)它现在正在工作。但有一件事你知道为什么当我大摇大摆地把
serviceProductId
放进去时,我无法收到它吗?我和邮递员试过了,效果还不错,但在《大摇大摆》中,我无法获得
服务产品ID
@FacundoGFlores。如果不知道你的大摇大摆配置,很难说。您可以发布一个新的问题,并添加更多与问题相关的信息,现在它正在工作。但有一件事你知道为什么当我大摇大摆地把
serviceProductId
放进去时,我无法收到它吗?我和邮递员试过了,效果还不错,但在《大摇大摆》中,我无法获得
服务产品ID
@FacundoGFlores。如果不知道你的大摇大摆配置,很难说。您可以发布一个新问题,并添加更多与swagger问题相关的信息