M# Tutorials

Learn to build .NET applications with M#. Our step-by-step tutorials will get you up-to-speed rapidly.
If you already know ASP.NET and C#, you can master M# in a week or two.

Dynamic menu items

Another cool feature in M# is the possibility to generate your menu items depending on values in the database. In this lesson we will learn how to create a menu for a status and display all the statuses.


To do this we have to add a new entity to our HelloWorld application. Create a new entity named "Status" and set the attributes "Instance accessors" and "Is enum reference" to "True".

Populate the Status entity with some data.

Finally add the status association to the Employee entity.

Now we have a typical scenario in an application, so let's create a dynamic menu on these statuses.


Our menu will acts like a filter, we want to redirect the user to a page which will display all the employees for the specified status.
Create a new custom item and give a value for the Name attribute.

This item will be our template for all dynamically generated items.
Set its "Data source type" attribute to "Status", which is equivalent to the "Data source" attribute set to the value


, that will get the list of statuses.
The text attribute corresponds to the displayed value, set it to "c#:ITEM.Name" to display the name of the current status. Note that the current status is in the object "ITEM".
Now add a navigation inside the item template and pass the status ID to the targeted page, rebuild your module, and now you should be able to see your menu containing all your statuses.

Selected value

As you may have noticed the selected menu item doesn't have the "selected" CSS class set to it.
To fix this set the attribute "Selected item value" of your menu to

return Request["id"];

, that will overwrite the generated code in the FindSelectedValue() method.

Associate static items

You can also add static menu items next to your dynamic items. To do this just create a new Item, implement it like a static item and move it around your dynamic items.