Skip to content

Optional parameters don't work #122

Closed
@mkatrikh

Description

@mkatrikh

There was controller in asp.net core 1.1 with action method with optional parameter:

[Route("api")]
 public abstract class BaseController {
        // omitted
        [HttpPost("[controller]/{id?}")]
        public virtual async Task<IActionResult> Post([FromBody]TDto dto, int? id, string[] include)
        {
              // omitted
         }
}

It worked. then versioning was added. and this pattern stops work:

[Route("api/v{version:apiVersion}")]
public abstract class BaseController {

with error

Microsoft.AspNetCore.Mvc.Versioninig.ApiVersionActionSelector[5] Multiple candidate actions were found, but none matched the requested service API version '1.0'. Candidate actions:

If I add constraint to route pattern for method ("[controller]/{id:int?}") it strats work again but only with supplied id value. The only solution I found was adding new action method with url template "[controller]".
Is it error or I missed something?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions