Sajith v
Sajith v

Reputation: 369

Disable orchard menu item in c#

I want to be able to disable a orchard menu item from a page without writing or changing any html code or javaScript.

I want to do this only from C#. I have used a NavigationProvider Class to do this.

 public class NavigationProvider : INavigationProvider
{
    public Localizer T { get; set; }
    public ILogger Logger { get; set; }
    private readonly IOrchardServices _orchardServices;
    public string MenuName
    {
        get { return "Menu"; }
    }
    public NavigationProvider(IOrchardServices orchardServices)
    {
        this._orchardServices = orchardServices;
    }
    public void GetNavigation(NavigationBuilder builder)
    {
        try
        {
            if (this._orchardServices.Authorizer.Authorize(Permission.View))
            {
                builder.Add(T("MenuItem1"), "1", item => item.Action("Index",
                "ControllerName",
                new { area = ModuleName }));
            }
            else
            {
                 builder.Add(T("MenuItem1"), "1", item => item.Action("Index",
                "ControllerName",
               new { area = ModuleName  }).AddClass("disabled").LocalNav(false)).

            }
        }
        catch (Exception ex)
        {
            Logger.Error(ex, "Error on building custom menu.");
        }
    }
}

Also tried to pass "style=pointer-events:none" instead of disabled

Upvotes: 0

Views: 129

Answers (1)

user6059646
user6059646

Reputation:

I have the same problem and you can hide that menu from this class. I guess this is the only solution to your problem. You can add icons using the addClass.

Upvotes: 2

Related Questions