1
我裝修的動作(在我的家庭控制器),像這樣:MVC屬性的路由問題
[Route("view-book")]
public ActionResult ViewBook(int? id1, string id2)
在我看來,我填充使用JavaScript的一些超鏈接:
tbody = tbody + '<a href="@Url.Action("ViewBook", "Home")/' + item.Id + '/' + item.Slug + '">View Book</a>';
與上面的代碼,超鏈接的URL呈現正確。例如:
https://localhost:44306/view-book/1/this-book
但是,ActionResult不會被擊中。於是,我改變路由的裝飾是:
[Route("view-book/{id1:int?}/{id2}")]
public ActionResult ViewBook(int? id1, string id2)
而且現在的URL渲染錯誤,像這樣:
https://localhost:44306/Home/ViewBook/1/this-prop
但是,如果我手動更改URL正確的URL像上面:
https://localhost:44306/view-book/1/this-prop
ActionResult然後被擊中!
我該如何解決這個問題?