I'm trying to create a link to the following GET action with Url.Action
:
public class FooController : Controller
{
[HttpGet]
[Route("Foo/Apply/BarDetails/Part/{id}")]
public IActionResult BarDetails(int id)
{
}
}
And in my view I'm creating a URL with
Url.Action("BarDetails", "Foo", new {id = 1})
However this generates the URL Foo/Apply/BarDetails/Part/10?id=1
which is definitely not what I want! Removing the values
parameter simply removes the query string part of the URL. The only route I have registered at startup is
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
I've had a look at the ASP.NET Core source and I suspect that the "10" part of the URL is coming from a "1" + "0"
operation somewhere as the routing code is split across 2+ repos it's hard to follow. Does anyone know how the last part of this URL is being generated and how I can fix it to match the id
provided in the route values?