MVC提供一些帮助函数创建链接,这些函数根据路径映射表自动调整生成的URL:
说明 | 示例 | 输出结果 |
应用程序相对URL | Url.Content("~/Content/Site.css") | /Content/Site.css |
到控制器action的链接 | Html.ActionLink("My Link", "Index", "Home") | <a href="/">My Link</a> |
Action的URL | Url.Action("GetPeople", "People") | /People/GetPeople |
使用路径映射的URL | Url.RouteUrl(new {controller = "People", action="GetPeople"}) | /People/GetPeople |
使用路径映射的链接 |
Html.RouteLink("My Link", new {controller = "People", action="GetPeople"}) |
<a href="/People/GetPeople">My Link</a> |
命名路径映射的链接 |
Html.RouteLink("My Link", "FormRoute", new {controller = "People", action="GetPeople"}) |
<a href="/app/forms/People/GetPeople">My Link</a> |