ActionLink and RountLink

In Global.asax file:

routes.MapRoute(
UpcomingDinners”, // rount name
“Dinners
/Page/{page}”,
new { controller = “Dinners”, action = “Index” }
);
routes.MapRoute(
“Default”,
// Route name
“{controller}/{action}/{id}”, // URL with params
new { controller=”Home”, action=”Index”,
id
=UrlParameter.Optional } // Param defaults
);

 

 

1. ActionLink uses the default route ( “{controller}/{action}/{id}”, ), therefore:

<%: Html.ActionLink(dinner.Title, “Details”, new { id=dinner.DinnerID }) %>  // the first parameter is the innerHTML of the <a></a> tag

the action will be Detail , and then will generate the html like this:

<a href=”/Dinners/Details/1”>.NET Futures</a>  

note, the view is "Dinner.ascx" so it will automatically get the corresponding controller, which is "Dinner"

2. RouteLink uses the specific route:

  <%: Html.RouteLink(“>>>”,   “UpcomingDinners”,   new { page = (Model.PageIndex + 1) })%>

as we can see the route of UpcomingDinners is  "Dinners/Page/{page}”, therefore, it will route to Dinner controller's Page method

 

 

 

 

 

 

 

posted @ 2011-02-05 05:18  Jian, Li  Views(160)  Comments(0)    收藏  举报