2013-12-10 4 views
0

@Html.MvcSiteMap().Menu("MenuBtnGroup") 대신 @Html.MvcSiteMap().PageMenu()을 입력하면됩니다.새 모델을 만드는 방법은 무엇입니까?

주로 필터 때문입니다.

나는 특정 링크는 페이지에 표시하거나이 기능은 내장되어 있지

<mvcSiteMapNode title="Usuários" controller="Usuarios" action="Index"> 
    <mvcSiteMapNode title="Novo Usuário" action="Novo" visibility="SiteMapPathHelper,PAGEMENU-ONLY,!*" /> 
    <mvcSiteMapNode title="Detalhes" action="Detalhes" visibility="SiteMapPathHelper,!*" dynamicNodeProvider="UsuarioDynamicNodeProvider, Web"> 
     <mvcSiteMapNode title="Editar" action="Editar" inheritedRouteParameters="id" /> 
    </mvcSiteMapNode> 
</mvcSiteMapNode> 

답변

1

(아직) 주요 응용 프로그램 메뉴에서 사이트 맵이 아닌 것을 좋겠지 만, 방법이 거기에있다 자신의 가시성 공급자를 만들고 SourceMetaData를 사용하여 메뉴의 이름을 가시성 논리에 전달하면됩니다.

/// <summary> 
/// Filtered SiteMapNode Visibility Provider for use with named controls. 
/// 
/// Rules are parsed left-to-right, first match wins. Asterisk can be used to match any control or any control name. Exclamation mark can be used to negate a match. 
/// </summary> 
public class CustomFilteredSiteMapNodeVisibilityProvider 
    : SiteMapNodeVisibilityProviderBase 
{ 
    #region ISiteMapNodeVisibilityProvider Members 

    /// <summary> 
    /// Determines whether the node is visible. 
    /// </summary> 
    /// <param name="node">The node.</param> 
    /// <param name="sourceMetadata">The source metadata.</param> 
    /// <returns> 
    ///  <c>true</c> if the specified node is visible; otherwise, <c>false</c>. 
    /// </returns> 
    public override bool IsVisible(ISiteMapNode node, IDictionary<string, object> sourceMetadata) 
    { 
     // Is a visibility attribute specified? 
     string visibility = string.Empty; 
     if (node.Attributes.ContainsKey("visibility")) 
     { 
      visibility = node.Attributes["visibility"].GetType().Equals(typeof(string)) ? node.Attributes["visibility"].ToString() : string.Empty; 
     } 
     if (string.IsNullOrEmpty(visibility)) 
     { 
      return true; 
     } 
     visibility = visibility.Trim(); 

     // Check for the source HtmlHelper 
     if (sourceMetadata["HtmlHelper"] == null) 
     { 
      return true; 
     } 
     string htmlHelper = sourceMetadata["HtmlHelper"].ToString(); 
     htmlHelper = htmlHelper.Substring(htmlHelper.LastIndexOf(".") + 1); 

     string name = sourceMetadata["name"].ToString(); 

     // All set. Now parse the visibility variable. 
     foreach (string visibilityKeyword in visibility.Split(new[] { ',', ';' })) 
     { 
      if (visibilityKeyword == htmlHelper || visibilityKeyword == name || visibilityKeyword == "*") 
      { 
       return true; 
      } 
      else if (visibilityKeyword == "!" + htmlHelper || visibilityKeyword == "!" + name || visibilityKeyword == "!*") 
      { 
       return false; 
      } 
     } 

     // Still nothing? Then it's OK! 
     return true; 
    } 

    #endregion 
} 

"이름"SourceMetadata 속성을 지정하여 각 메뉴의 이름을 지정할 수 있습니다.

@Html.MvcSiteMap().Menu(new { name = "MainMenu" }) 
@Html.MvcSiteMap().Menu(new { name = "PageMenu" }) 

그리고 당신의 구성에서 FilteredVisibilityProvider 대신 CustomFilteredSiteMapVisibilityProvider를 사용합니다. 전체 예제는 this answer을 참조하십시오.

관련 문제