MVC 6 Anchor Tag Helper does not produce the expected href

Pretty simple problem.

<a asp-controller="Guide" asp-action="Index" asp-route-title="@Model.Title">Read more</a>

creates a link / guide? title = Guide_no_1 , but it is assumed that it will create a link / Guide / Guide_no_1 /

The documentation that I can find indicates that it should output / Guide / Guide_no_1 / , so I feel like I missed something, a parameter, or some attribute somewhere.

the routes that I have just affect link building

[Route("/Guide/")]
public IActionResult Index() { ... }

[Route("/Guide/{title}/{page?}/")]
public IActionResult Index(string title, int page = 0) { ... }

[Route("/Guide/OnePage/{title}/")]
public IActionResult Index(string title) { ... }
+4
source share
1 answer

You need to specify the order of the attribute routes.

  • , , , . /Guide/, , , .

, . , :

[Route("Guide/OnePage/{title}/", Order = 1)]
public IActionResult Index(string title) { ... }    

[Route("Guide/{title}/{page?}/", Order = 2)]
public IActionResult Index(string title, int page = 0) { ... }

[Route("Guide/", Order = 3)]
public IActionResult Index() { ... }
  • , , , , Order . , .

, Guide/OnePage/{title}/ Guide/{title}/{page?}/. , , MVC , , , !

  • .
  • , , , :

    [Route("Guide/{title}/{page?}/", Name = "titleAndPage", Order = 2)]
    public IActionResult Index(string title, int page = 0) { ... }
    
    <a asp-route="titleAndPage" asp-route-title="fooTitle">Read more</a>
    
+4

All Articles