Read all the advantages of using ApiControllerAttribute
, however, if we want to have optional parameter while using this attribute for query parameter, it doesn't work. It still validates all parameters as mandatory. Any idea how to make it optional?
[ApiController]
public class testController: ControllerBase
{
[HttpGet("employees/{id?}")]
public List<Employees> GetAll(int? id)
{
// gets all employees or by id
}
}
When this code is executed, it expects id
all the time. It does not run without this parameter.
EDIT: it doesnt work even when default value of id is passed.