At the beginning of the function, it was found that a "breadcrumbs" navigation feature was interspersed across all the pages. This seemingly insignificant little feature had not been noticed before, and now decided to implement it
So-called breadcrumbs, which are page-level navigation, such as
Home >> My Blog >> essays
The structure was observed and analyzed as follows:
1. Structure must be a parent-child structure, that is, a tree structure
2. It is necessary to store the data of this structure in advance and load it dynamically on the page.
Well, the idea has to start to realize. First of all, the solution to this tree structure is to use either the database or the XML, but I don't want to read the file with IO in the project, so I decided to use the database to build the table (T_navigator), including the Id,action,control,name,parentid field. Where action puts the action name of the page, control puts the controller name, name puts the page name, ParentID puts the upper page address
Use HttpRuntime.Cache.Insert in global Application_Start to read the database T_ The list of navigator tables is put into Httpruntime.cache, of course, here can also use static global variables or Httpcontext.cache, but with httpruntime performance will be better, especially when the amount of data is large.
Next, you get the view and control of the current page in the template view.
Gets the current page control name
String control = ViewContext.RouteData.Route.GetRouteData (this. Context). values["Controller"]. ToString ();
Get the current page action name
String action = ViewContext.RouteData.Route.GetRouteData (this. Context). Values["Action"]. ToString ();
Then extend HtmlHelper, write an extension method that returns the Mvchtmlstring type Getnavigator (control, action), First get the list of navigation information in Httpruntime.cache, then pass in action and control, find the ID and name of the current page, iterate through the ID and name of all the parent pages, depending on the front-end requirements (such as a tag or span or other label), Stitching into the form of xxx>>xxx>>xxx, and then returning mvchtmlstring
Finally, use the @Html. Getnavigator (Control, action) on the template view to get breadcrumb navigation.
There are several points to note when using this method:
1. When adding a view or new action, whenever you want to refresh the page, add the corresponding information in the T_navigator.
2.t_navigator added a new page and needs to restart IIS or rebuild because the data in T_navigator is loaded into the cache
The development of large business-to-business website 2