如何使用 MvcSiteMap 为 ASP.Net MVC2 创建站点地图节点
我想使用 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();
}
}
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 = "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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还必须设置密钥:
You'll have to set the key as well: