This kind of question has been asked before on SO (post 1, post 2, post 3), but none of them was able to help me.
I have the following route (defined inside a LandingController class):
[HttpGet]
[Route("connections/{city:name}/map{page?}", Order = 2)]
public Task<ActionResult> Connections(string city, int page = 1)
for which I am trying to generate an URL in my Razor template like this:
@Url.Action("Connections", "Landing", new { city = "madrid", page = 1 })
or
@Url.Action("Connections", new { city = "madrid", page = 1 })
Both these calls return null. Anyone has an idea why?
However if I omit the page parameter in the route template (doing [Route("connections/{city:name}/map", Order = 2)]), the following URL is generated: /connections/madrid/map/?page=1, which is not what I want, but it shows that I am doing something wrong with my calls above.
[Route("connections/{city:name}/map/{page?}]?CurrentCultureand it turned out that the routing info for that specific culture was not set up in the database where we keep our routing configuration, and I kept gettingnulls. Basically, getting null from@Url.Actionmeans that the route you are looking for has not been configured and does not exist. I was not aware that we saved route configs in the database at the time.