How to allow an empty request body for a reference type parameter?
You can make it a optional parameter by assigning a default value null
and specifying explicitly that the values will be coming as part of request url
[HttpGet]
public ActionResult<IEnumerable<MyModel>> Get([FromQuery]MyRequest myRequest = null)
{
BTW, a GET
operation has no body and thus all the endpoint parameter should be passed through query string (Or) as Route value.
You should specify a routing in your api end point and have the values passed through route and querystring. something like
[HttpGet("{IncludeProperties}")]
//[Route("{IncludeProperties}")]
public ActionResult<IEnumerable<MyModel>> Get(string IncludeProperties = null, IEnumerable<string> Filters = null)
{
With the above in place now you can request your api like
GET api/myModels?Filters=
Do this:
services.AddControllersWithViews(options =>
{
options.AllowEmptyInputInBodyModelBinding = true;
});