Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MainMenu.xml file - is there a way to make it dynamic?
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Titre:
MainMenu.xml file - is there a way to make it dynamic?
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01602055
Message ID:
01602055
Vues:
47
Hi everybody,

In our code to produce a menu we use MainMenu.XML file with entries such as
      <menuMapNode title="User Defined Code #1" action="Index" controller="UserCodes1" area="Reservations" icon="" roles="T_USERCOD1" />
      <menuMapNode title="User Defined Code #2" action="Index" controller="UserDefinedCode2" area="Reservations" icon="" roles="*" />
The problem for this particular part of the menu that the title should not be really 'User Defined Code #'. This title should be read from a database.

I am wondering how can we still use the XML file but yet for certain menu use some properties? Should we keep the XML file as is but change title in the code that works with that XML menu file?

Thanks in advance.

----------------
Looking closer in the code I found a method that builds the menu tree
private List<MainMenuListItem> BuildMenuItemTreeFromMapNodeTree(MenuMapNode menuMapNode, string opCode)
        {
            // Recursively build a tree of MainMenuListItems from a MenuMapNode tree (the MenuMapNode
            // tree is a tree of nodes representing a hierarchical menu map).  The MainMenuListItems tree 
            // will be trimmed according to the users's roles and can be used to build a menu in the UI.

            var query = (from mapNode in menuMapNode.SubNodes
                         select new MainMenuListItem(mapNode.Roles)
                         {
                             Text = mapNode.Title,
                             NavigateUrl = _UrlHelper.Action(mapNode.Action, mapNode.Controller, new { area = mapNode.Area }),
                             Icon = mapNode.Icon,                            
                             Children = BuildMenuItemTreeFromMapNodeTree(mapNode, opCode),
                             AreaName = mapNode.Area,
                             ControllerName = mapNode.Controller,
                             ActionName = mapNode.Action
                         }).Where(menuItem => menuItem.IsRoleMatch(_UsersRoles, opCode)).ToList();

            return query;
        }
So, one possibility I see here is to change

Text = mapNode.Title

into, say, Text = GenerateDynamicText(mapNode.Title)

and do it using switch statement and checking for direct title descriptions and translate this way. Does it sound like an OK approach or you see something better?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Répondre
Fil
Voir

Click here to load this message in the networking platform