Routing System In Asp.net MVC3-Outgoing URLs

URLs In Views

 

Action Links:(Extension Method For HtmlHelper)

@Html.ActionLink("About this application", "About") ——Returns an anchor element (a element) that contains the virtual path of the specified action.

The parameters to the ActionLink method are the text for the link and the name of the action method that the link should target.

 

The HTML that the ActionLink method generates is based on the current routing schema.When we supply values for properties that do not correspond with segment variables, the values are appended to the outgoing URL as the query string.

URL Pattern :

routes.MapRoute("MyRoute", "{controller}/{action}/{id}",new { controller = "Home", action = "Index", id = UrlParameter.Optional });
 

ActionLink Helper Method:

@Html.ActionLink("About this application", "About",new { id = "MyID", myVariable = "MyValue" })

 

Outgoing URL:

<a href="/Home/About/MyID?myVariable=MyValue">About this application</a>

 

If we supply a value for a variable that happens to match the default value we specified in the route,then the routing system omits the variable from the outgoing URL.

ActionLink Helper Method:

@Html.ActionLink("About this application", "Index", "Home")

 

Outgoing URL:

<a href="/">About this application</a>

 

URLs For Displaying:(Extension Method For UrlHelper)

@Url.Action("Index", "Home", new { id = "MyId" })——Generates a fully qualified URL to an action method for the specified action name and route values.

The Url.Action method works in the same way as the Html.ActionLink method, except that it generates only the URL.

 

URLs In Actions

 

protected internal virtual RedirectToRouteResult RedirectToRoute(string routeName, RouteValueDictionary routeValues);
protected internal RedirectToRouteResult RedirectToAction(string actionName);——Redirects to the specified action using the action name.
 
posted @ 2012-02-03 17:07  HelloWorld.Michael  阅读(256)  评论(0)    收藏  举报