I am using [FromQuery]
atribute in controller's Get
method:
//CarsController, etc..
[HttpGet]
public async Task<ActionResult<IEnumerable<CarsDto>>> Get([FromQuery] CarsParameter? carsParam = null)
{
//param is always not null here
}
Inside the method I need to distinguish between api/cars
and api/cars?color=red
calls. Problem is, that carsParam
object is never null, so I cannot say if the Color=""
(defailt value) is intended to be empty string or it's because of the call was api/cars
CarsParameter
is a simple class:
public class CarsParameter
{
public string Color {get; set;} = "";
//more params here
}
Yes, I can use different path, like api/cars/withParams?color=red
, but i am looking for more subtle solution.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…