Home When I use Html.ActionLink, I find that @Html.ActionLink("Home", ...">

Why @ Html.ActionLink ("Home", "Index", "Home") generates <a href= "\"> Home </a>

When I use Html.ActionLink, I find that @Html.ActionLink("Home", "Index", "home") generates this line <a href="\">Home</a> , so why is the address \home\index becomes \ , I found that this is due to the default route set in web.conf. I looked at mvc 3 source code, but I can not find the answer. Who can help me? Thanks.

+4
source share
2 answers

This is because of the default route. If you do not specify a default action and a controller, it will generate /home/index as url.

 routes.MapRoute( "Default", "{controller}/{action}/{id}", new { id = UrlParameter.Optional } ); 
+5
source

bidirectional routing:
- in: it converts incoming urls to controller / actions / parameters
- out: it converts the controller / actions / parameters to urls

+2
source

Source: https://habr.com/ru/post/1393969/


All Articles