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

2
  • Possible duplicate of Optional Parameters in Web Api Attribute Routing Commented Nov 15, 2016 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. Commented Nov 15, 2016 at 21:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.