Je décore une action (dans mon contrôleur Home) comme si:problèmes de routage d'attributs MVC
[Route("view-book")]
public ActionResult ViewBook(int? id1, string id2)
À mon avis, je renseigner certaines hyperliens en utilisant javascript:
tbody = tbody + '<a href="@Url.Action("ViewBook", "Home")/' + item.Id + '/' + item.Slug + '">View Book</a>';
Avec le code ci-dessus, l'URL du lien hypertexte s'affiche correctement. E.g:
https://localhost:44306/view-book/1/this-book
Cependant, le résultat ActionResult n'est pas atteint. Alors, je change la décoration de routage être:
[Route("view-book/{id1:int?}/{id2}")]
public ActionResult ViewBook(int? id1, string id2)
Et maintenant l'URL Renders de manière incorrecte comme ceci:
https://localhost:44306/Home/ViewBook/1/this-prop
Cependant, si je change manuellement l'URL à l'URL correcte comme ci-dessus:
https://localhost:44306/view-book/1/this-prop
Le résultat ActionResult est alors atteint!
Comment résoudre ce problème?