Hi,
I have a Web API which accepts 3 string parameters and all of them can be null.
Please see below:
[HttpGet]
public IEnumerable<proc_GetStudents_Result> Get(string id, string surnam, string forenam)
{...}
It does a wildcard search for the records in the database.
I have WebAPi.config.cs with following Route mapped:
config.Routes.MapHttpRoute(
name: "StudApi",
routeTemplate: "studapi/{controller}/{id}/{surnam}/{forenam}",
defaults: new
{
id = RouteParameter.Optional,
surnam = RouteParameter.Optional,
forenam = RouteParameter.Optional
}
);
If I give values to all the 3 parameters I get the search result from database as expected. But If I give value to just one of them, e.g. 'forenam', the Web Api does not accept null values for 'id' and 'surname'. Instead, it assigns the value given for 'fornam' to the first parameter i.e. 'id' and null values to the 'surnam' and 'forenam'. The Search result I get is not as expected.
I am new to Web API and I referred many threads, but did not get a solution for mine. Can any one help me on this?
Thanks in advance!! :)