【发布时间】:2017-09-20 04:00:42
【问题描述】:
我像这样装饰一个动作(在我的 Home 控制器中):
[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 然后被击中!
我该如何解决这个问题?
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-routing