Address: http://space.itpub.net/740297/viewspace-586997
1. create an extension method for the urlhelper class to generate a relative path URL. Do not pass the controller, behavior, or route name everywhere as a string. Create an extension method for urlhelper to encapsulate them. For example: 1.
Public static class urlhelperextension 2.
{3.
Public static string home (this urlhelper helper) 4.
{5.
Return helper. Content ("~ /"); 6.
} 7.
8.
Public static string signup (this urlhelper helper) 9.
{10.
Return helper. routeurl ("signup"); 11.
} 12.
13.
Public static string dashboard (this urlhelper helper) 14.
{15.
Return dashboard (helper, storylisttab. unread); 16.
} 17.
18.
Public static string dashboard (this urlhelper helper, storylisttab tab) 19.
{20.
Return dashboard (helper, tab, orderby. createdatdescending, 1); 21.
} 22.
23.
Public static string dashboard (this urlhelper helper, storylisttab, orderby, int page) 24.
{25.
Return helper. routeurl ("dashboard", new {tab = tab. tostring (), rderby = orderby. tostring (), page}); 26.
} 27.
28.
Public static string Update (this urlhelper helper) 29.
{30.
Return helper. routeurl ("Update"); 31.
} 32.
33.
Public static string submit (this urlhelper helper) 34.
{35.
Return helper. routeurl ("Submit"); 36.
} 37.
} In this way, you can use the following in the View: 1.
<A href = "<% = URL. dashboard () %>"> dashboard </a> 2.
<A href = "<% = URL. Profile () %>"> profile </a> instead of the following: 1.
<% = Html. actionlink ("dashboard", "dashboard", "story") %> 2.
<A href = "<% = URL. routeurl (" Profile ") %>"> profile </a> and can be used in the Controller as follows: 1.
Return redirect (URL. dashboard (storylisttab. Favorite, orderby. createdatascending, 1) instead of: 1.
Return redirecttoaction ("dashboard", "story", new {tab = storylisttab. Favorite, rderby = orderby. createdatascending, page = 1 });
Related reading:
- ASP. net mvc unleashed (5)(Geez, 2009-3-12)
- ASP. net mvc unleashed (5) (continued)(Geez, 2009-3-13)
- ASP. net mvc unleashed (6)(Geez, 2009-3-17)
- ASP. net mvc 1.0 officially released(Geez, 2009-3-18)
- ASP. net mvc unleashed (6) (continued)(Geez, 2009-3-21)
- ASP. net mvc technology topics(Zhu Xianzhong, 2009-3-27)
- Action filter for ASP. net mvc notes (idotnetspace)
- ASP. net mvc: analyze the tempdata mechanism (idotnetspace)
- ASP. net mvc Futures: MVC control Overview (geez, 2009-4-09)
- ASP. net mvc Futures: local view(Geez, 2009-4-10)