当我使用Html.ActionLink,我发现@Html.ActionLink("Home", "Index", "home")
产生这个字符串<a href="\">Home</a>
,何必地址\home\index
变得\
,我发现这与web.conf中设置的默认路由有关。我查看过mvc 3源代码,但找不到答案。谁能帮我?谢谢。为什么@ Html.ActionLink(“家”,“索引”,“家”)产生<a href="">Home</a>
4
A
回答
5
这是由于默认路由。如果您不指定默认操作和控制器,它将生成/home/index
作为url。
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { id = UrlParameter.Optional }
);
2
路由是双向的:
- 在:它进入的网址转换成控制器/动作/参数
- 退房:控制器/动作/参数转换成网址
相关问题
- 1. @ Html.ActionLink到<a href="@Url.Action()>
- 2. href表达式<a href="javascript:;"></a>做什么?
- 3. <a href="#">Click here</a>是什么意思?
- 4. 什么<a href="#" class="view"> mean?
- 5. Html.ActionLink()与<a>标签
- 6. <a href=""></a>不工作
- 7. 产生的.docx使用<a href="http://www.aspose.com/" rel="nofollow">aspose</a></p> <p>然而aspos
- 8. 字体家族财产上<nav>
- 9. 为什么在一个母版页运行成为<a href="#link#link">当<a href="~/#link">?
- 10. <a href=...> syntax
- 11. <a href="#!"> do?
- 12. 这个链接有什么问题? <a href="#"onclick="getNextPage();">next></a>
- 13. 搜索字符串格式,直到<a href="https://wiki.gnome.org/Apps/Evolution" rel="nofollow noreferrer">evolution</a>产生匹配
- 14. 为什么(![] + [])[+ !! [] + []]产生“a”
- 15. jQuery - target.href与<a href="#"><img></a>
- 16. <a href=#>链接重定向到索引。 PHP的?
- 17. 为什么我的<a href="test.xls"> is working and .txt is not?
- 18. <a href="somewebsite.com">需要到localhost/somewebsite.com,为什么?
- 19. XPath检索<a> href,文本和<span>
- 20. <A href> adding " to URL
- 21. 我该怎么做<a href>?
- 22. 由<a href="https://overviewer.org/" rel="nofollow">Minecraft Overviewer</a>产生的混合通配符和参数的快速
- 23. 传入<a href>
- 24. 用<a href> tags
- 25. 在<a href="form.submit();">
- 26. CSS和<a href> issue
- 27. 与HTML <a href...>
- 28. href锚文本</a>
- 29. <a href> inside mobile:SelectionList
- 30. 使用<a href= > tag
可以查找和更改默认在Global.asax文件中路由 – Kaido 2012-01-31 12:58:04
我认为路由是分析请求的url,但ActionLink是生成一个url,而不是来自浏览器的请求,它为什么会受到路由的影响? – avatas 2012-01-31 13:10:48
@avatas,所有与urls一起工作的HTML助手都会在生成这些url时使用您的路由定义。所以他们肯定受到路线的影响。 – 2012-01-31 13:11:30