Search code examples
asp.net-mvcsolid-principlesaspnetboilerplate

How do I add a new menu to an aspnetboilerplate based project?


This has been asked before but I'm going to be more precise with my question to hopefully get a better answer:

I have figured out how to add views to the PageNames class:

public const string WorkOrders = "WorkOrders";

and then to the projectNavigationProvider class to get them in to the navbar:

         .AddItem(
            new MenuItemDefinition(
                    PageNames.WorkOrders,
                    L("WorkOrders"),
                    url: "WorkOrders",
                    icon: "business",
                    requiredPermissionName: PermissionNames.Pages_WorkOrders
                )

To get my main views added to the main navbar and working properly.

However, I have not figured out how to create a totally new menu to be used elsewhere. In the app I'm working on we have several pages that display all of the records in a particular table, Work Orders for example. But each record in each table should have several links to other pages for create, edit, details and delete.

One of my partners seems to have solved this problem on other pages by using modals and ajax calls to the controllers endpoints. It works fine for the Customers, which only require name and contact info., but I don't think a modal will work for creating, viewing or editing a Work Order becuse it requires adding line items and the associated data for each one of them etc... There's a lot to it. Lastly, it doesn't seem like the template is set up to be used that was as he wrote a lot of his own js to get it working.

Currently, the create, edit, and details views exist and I have links to them next to each record but I get errors when I try to use the link. Maybe I don't understand how the routing works? In the normal mvc template from VS the links have properties for specifying the controller and method and mvc handles the rest.

<a asp-action="Edit" asp-route-id="@item.WorkOrderID">Edit</a> |
<a asp-action="Details" asp-route-id="@item.WorkOrderID">Details</a> |
<a asp-action="Delete" asp-route-id="@item.WorkOrderID">Delete</a>

I'm getting the same error I had when trying to get the Work Orders page to load but had not added it to pagenames or navigationprovider, which makes me thing I just need to add the links to the navigationprovider class but I don't want a link the the WordOrders create page on the main menu, I want it on a mini menu next to the corresponding record. I have added the page to the pagenames class but am not sure how to create a separate menu for my main page.

public const string CreateWorkOrders = "CreateWorkOrders";

In reviewing the navigationprovider class I see:

 context.Manager.MainMenu

and I'm thinking I must be able to create another menu and add items to it like this:

 context.Manager.NewMenu.AddItem(....

but it looks like MainMenu is referenced in a class that I can't find or edit. Should I be creating another class defining the NewMenu so I would be able to configure it in the existing navigationprovider class or should I be creating a separate navigationprovider class for it?

Hopefully I've convinced everyone who looks at this that I have done plenty of research before reaching out for help. Even a link to some more detailed documentation would helpful.


Solution

  • You can add a new menu like this:

    context.Manager.Menus.Add(WorkOrders, new MenuDefinition(WorkOrders, L(WorkOrders)));
    

    Usage:

    context.Manager.Menus[WorkOrders].AddItem(...)