我想使用MvcSiteMap来定义我的控制器和动作的站点地图,让我生成面包屑和菜单。
我尝试使用下面的装饰器以编程方式添加节点,但不幸的是它不会像我想要的那样使我的树。
[MvcSiteMapNodeAttribute(Title = "Home"]
[MvcSiteMapNodeAttribute(Title = "Services", ParentKey = "Home")]
[MvcSiteMapNodeAttribute(Title = "Service detail", ParentKey = "Services")]
[MvcSiteMapNodeAttribute(Title = "Edit", ParentKey = "Service detail")]
我如何装饰我的行为以确保按照我想要的方式建立子/父关系?
[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();
}
}
答案 0 :(得分:0)
您还必须设置密钥:
[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")]