How to create grouping and clickable nodes from single action simultaneously?

纵然是瞬间 提交于 2020-01-06 14:07:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!