【发布时间】:2016-07-16 05:09:13
【问题描述】:
根据我应用的属性路由,我无法让@Url.Action 解析为我期望的 url:
我的操作(SearchController 但使用 [RoutePrefix("add")])
[Route("{searchTerm}/page/{page?}", Name = "NamedSearch")]
[Route("~/add")]
public ActionResult Index(string searchTerm = "", int page = 1)
{
...
}
调用 Url.Action
@Url.Action("Index", new { controller = "Search", searchTerm = "replaceMe", page = 1 })
这会产生一个 url
/add?searchTerm=replaceMe&page=1
我希望
/add/replaceMe/page/1
如果我手动输入 url,那么它会使用正确的参数解析为正确的操作。为什么@Url.Action 不能解析正确的url?
【问题讨论】:
标签: asp.net-mvc routes url-routing asp.net-mvc-routing attributerouting