I've an Action in my ApiController that I want to invoke from a specific link, so I created this simple route
[Route("Rest/GetName/{name}")]
public IHttpActionResult GetName(string name) {
// cut - code here is trivial but long, I just fill in an object to return as Json code
return Json(myObject);
}
It works fine but I want to make the parameter optional. According to documentation adding a question point at the end of the parameter name in the route should be enough
[Route("Rest/GetName/{name?}")]
This way I get an error if I don't provide the optional parameter, so
.../Rest/GetName/AnyName --> ok
.../Rest/GetName/ --> error (see below)
{"Message":"No HTTP resource was found that matches the request URI 'https://localhost/miApp/Rest/GetName'.","MessageDetail":"No action was found on the controller 'Rest' that matches the request."}