ASP.NET MVC using the extended Attribute Title and Sitemap
How to use ASP.NET MVC Attribute extended Title and Sitemap?
See below.:
It is above to see the effect:
[usage: ASP.NET MVC Controller]
[usage: ASP.NET MVC View]
[summary].
As long as the Controller and Action plus Attribute can set the Controller name and the Action name.
Set the MVC Controller and MVC Action property
[NewPath("Demo", Controller = "Home", Action = "Index")] public class HomeController : Controller { [NewPath("The home page", Controller = "Home", Action = "Index")] public ActionResult Index() { ViewData["Message"] = "Welcome to the ASP.NET MVC!"; return View(); } public ActionResult About() { this.SetNewPath("About", new { Controller = "Home", Action = "About" }); return View(); } }
Here, I this site name is Demo, I give all the Controller with the name Demo and the related information can be
Then, there are two pages, are “ &rdquo and “ a home;”
I just added on Action their names and related information.
Q1: If you can add a Attrubute?
A1: Can, but also can be set to Order to set the order in which they
Q2: I need, name of the website, home page, the title of the article, how to do such a path?
A2: The code below, in addition to the settings in Attrubute outside, can also be set in the Action code, because some information need to be processed in order to get
[NewPath("Demo", Controller = "Home", Action = "Index", Order = 1)] [NewPath("The home page", Controller = "Home", Action = "Index", Order = 2)] public class HomeController : Controller { [NewPath("Journalism", Controller = "News", Action = "Index")] public ActionResult Detail(int? id) { this.SetNewPath("News headlines", new {Controller = "News", Action = "detail", id = id.Value}); return View(); } }
Displayed in the ASP.NET MVC View
The above code is placed in the MasterPage, because they use are all calls to the same function
In addition to the two main functions provided above, there is a very free function:
<h2><%=Html.GetSitemap() %></h2> <h2><%=Html.GetWebPath("<a href=\"{1}\">{0}</a>", " / ") %></h2>
Here, as long as the incoming display templates and separator template, you can optionally custom content.
Source
Posted by Mamie at November 15, 2013 - 3:05 AM