I am trying to build a helper to create a simple single level menu. Upon calling the menu helper I would like to use object literal notation so that I can define the menu items in the view.
public class ActionsMenuHelper
{
public static string ActionsMenu(IList<ActionsMenuItem> menuItems)
{
string result = "";
return result;
}
}
I am just not sure on the syntax to call the menu.
I have tried something like.
@ActionsMenuHelper.ActionsMenu(List<ActionsMenuItem>{ new {Name = "Foo"},
new {Name = "Bar"}
});
I’m obviously lost on how to do this.
You’re quite close. Try this:
Can get a little messy if you have more than a couple items, though. I’d define the list ahead of time for readability:
More information can be found here.