I want to use MvcSiteMap to define a sitemap of my controllers and actions, to let me generate breadcrumbs and menus.
I have tried using the below decorators to add nodes programmatically, but unfortunately it will not make my tree like I want.
[MvcSiteMapNodeAttribute(Title = "Home"]
[MvcSiteMapNodeAttribute(Title = "Services", ParentKey = "Home")]
[MvcSiteMapNodeAttribute(Title = 开发者_如何学Go"Service detail", ParentKey = "Services")]
[MvcSiteMapNodeAttribute(Title = "Edit", ParentKey = "Service detail")]
How can I decorate my actions to make sure the child/parent relations are made how I want?
[HandleError]
public class HomeController : Controller
{
// Home
public ActionResult Index ()
{
return View();
}
}
[HandleError]
public class ServiceController : Controller
{
// Home > Services
public ActionResult Index ()
{
return View();
}
// Home > Services > Service detail
public ActionResult Details (int id)
{
return View();
}
// Home > Services > Service detail > Edit
public ActionResult Edit (int id)
{
return View();
}
}
You'll have to set the key as well:
[MvcSiteMapNodeAttribute(Key = "Home", Title = "Home"]
[MvcSiteMapNodeAttribute(Key = "Services", Title = "Services", ParentKey = "Home")]
[MvcSiteMapNodeAttribute(Key = "ServiceDetail", Title = "Service detail", ParentKey = "Services")]
[MvcSiteMapNodeAttribute(Title = "Edit", ParentKey = "ServiceDetail")]
精彩评论