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.