Reputation: 21
My route is: [HttpGet] [Route("General/GetStreetsOfCityByText/{cityCode}/{txt}")] public IResult GetStreetsOfCityByText(int cityCode, string txt) {….} the string txt can be null. For enabling nullable parameter, I used MapHttpRoute: config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute( name: "optionalText", routeTemplate: "General/GetStreetsOfCityByText/{cityCode}/{txt}", defaults: new { txt = RouteParameter.Optional }); I try to invoke: http://localhost:56721/General/GetStreetsOfCityByText/3000/ But still gets 404 page not found I don't get what am I doing wrong
Upvotes: 0
Views: 43
Reputation: 21
Someone showed me a solution: Add, in the route template, a * befaore the nullable paramter. Like this: [Route("General/GetStreetsOfCityByText/{cityCode}/{*txt}")] This tells that this parameter may not exist in the invoke URL
Upvotes: 0