0

I have a function like below

public CaseController{

[HttpGet(GetAll/{parameter1:maxlength(50)?}/{parameter2:maxlength(50)?}/{parameter3:maxlength(50)?})
public IEnumerable<CaseDomainModel> GetAll(string parameter1 = null,string parameter2 = null,string parameter3 = null)
{
   // Code Goes here 
}
}

The api call generated goes like this

api/case/GetAll/value1 or api/case/GetAll//value2 or or api/case/GetAll///value3

which ever value is passed from the front end to this particular api method the value is getting passed to parameter1.

I searched SO and tried to follow Optional Parameters in Web Api Attribute Routing but unable to find a resolution.

My project is Angular 2 front end + webapi2 with asp.net core as a service layer.

Could you please let me know how to make webapi2 understand my optional parameters

Community
  • 1
  • 1
S_developer
  • 252
  • 5
  • 18
  • Possible duplicate of [Optional Parameters in Web Api Attribute Routing](http://stackoverflow.com/questions/22778640/optional-parameters-in-web-api-attribute-routing) – Daniel Corzo Nov 15 '16 at 20:54
  • You should probably just use query parameters.. No way for Web API to know which one you meant to specify. And routes like api/case/GetAll///value3 are not valid. Web API sees api/case/GetAll/value3 and assigns that to parameter1 as it should. – juunas Nov 15 '16 at 21:06

0 Answers0