问题
I have controller Account and its method LogOn. How to create sitemap like this:
-Account // non clickable, just grouping
--Log On // clickable
? If I use site map in the form of XML-file (mvc.sitemap) I can write like this:
<mvcSiteMapNode
title="Account"
controller="Account"
action="LogOn"
clickable="false"
key="AccountGroup" >
<mvcSiteMapNode
title="Log On"
controller="Account"
action="LogOn"
key="LogOn" />
</mvcSiteMapNode>
But I want to do it with only MvcSiteMapNodeAttribute attribute. However, only one such attribute can be applied to the method. I also don't want to use some dummy method to create just grouping node.
For now I have only one approach - create grouping nodes in the XML mvc.sitemap file, and clickable nodes - with MvcSiteMapNodeAttribute attribute. But I want to escape to write site map by hands as far as possible. Can it be done without grouping nodes in the XML?
回答1:
If using v4, you can apply multiple MvcSiteMapNodeAttributes to a single action method.
//
// GET: /Account/LogOn
[MvcSiteMapNodeAttribute(Title = "Account", ParentKey = "Home", Key = "AccountGroup", Clickable = false)]
[MvcSiteMapNodeAttribute(Title = "Log On", ParentKey = "AccountGroup", Key = "LogOn")]
public ActionResult LogOn()
{
return View();
}
You can also put the grouping node on the controller class if that is what you prefer (even in v3).
[MvcSiteMapNodeAttribute(Title = "Account", ParentKey = "Home", Action = "LogOn", Key = "AccountGroup", Clickable = false)]
public class AccountController
{
// Implementation here
}
来源:https://stackoverflow.com/questions/20285752/how-to-create-grouping-and-clickable-nodes-from-single-action-simultaneously