开发者

How can I create sitemap nodes for ASP.Net MVC2 using MvcSiteMap

开发者 https://www.devze.com 2023-01-23 10:06 出处:网络
I want to use MvcSiteMap to define a sitemap of my controllers and actions, to let me generate breadcrumbs and menus.

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")]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号