0

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

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.