Opening
Whether in Asp.net or MVC, it is always troublesome to set the website title or sitemap (without controls.
Title and sitemap are associated, so is there any way to write once and run anywhere?
Let's take a look at the effect and usage ~
[Effect]
[Usage: In controller]
[Usage: View]
[Usage Summary]
You only need to add attribute to the Controller and action to set the name of the current controller and action.
Set the attributes of controller and action
[Newpath ("Demo", controller = "home", Action = "Index")] public class homecontroller: controller {[newpath ("Homepage", controller = "home ", action = "Index")] public actionresult index () {viewdata ["message"] = "Welcome to ASP. net MVC! "; Return view ();} public actionresult about () {This. setnewpath ("about", new {controller = "home", Action = "about"}); Return view ();}}
Here, my website name is demo, so I can add the demo name and related information to all controllers.
Then there are two pages: "Homepage" and "about"
Then I only need to add their names and related information to the action.
Q1: Can multiple attrubute be added?
A1: Yes, and order can be set to set their order.
Q2: What should I do if I need a path like website name, home page, article, and article title?
A2: the code is as follows. In addition to setting it in attrubute, you can also set it in action code, because some information needs to be processed before obtaining
[Newpath ("Demo", controller = "home", Action = "Index", order = 1)] [newpath ("Homepage", controller = "home ", action = "Index", order = 2)] public class homecontroller: controller {[newpath ("news", controller = "news", Action = "Index")] public actionresult detail (Int? ID) {This. setnewpath ("news title", new {controller = "news", Action = "detail", id = ID. value}); Return view ();}}
Display in view
Generally, the code is put in masterpage, because their usage is to call the same function.
In addition to the two main functions provided above, there is also a very free function:
Here, you only need to input the display template and delimiter template to customize the content at will.
Source code and Examples