My First MVC Asp.net Website - Advice needed

greggpb

Expert Member
Joined
Apr 22, 2005
Messages
1,818
Reaction score
0
Location
Cape Town
Hi guys, I am doing my first ASP.net MVC Website and i need some advice, the last time i did a website ti was php and frames.. lol

I have tried to implement the mvc frame work. and i need some advice on menu's and structure..

I have built a menu model which pretty much has a tree structure in it and it is queried in my master layout page to build the main menu and page specific menu..

How would you guys achieve something like this ? what is the best practise or somthing that works in the real world..should each page have its own custom sub menu...
 
Last edited:
Not really sure what you are asking...

Personally I would make the menu a view. The controller then populates the menu view based on what you want. In your case for every page, populate the menu view with whatever is appropriate for that page.

To break it down, this is usually how I do it:
I almost exclusive use Java (because we use it at work), mostly spring/grails combined with GWT.

Then I have a root view. The root view usually has a menu object and a content object (which are normally panels). The menu is then drawn by the controller. I don't normally have more than one menu configuration so I just instantiate the menu directly in the root view and populate the menu panel. But in your case I would have the controller populate the menu every time based on what the requirement is. The menu would be a class that takes some kind of configuration so that every view's menu differs.

The views are also populated in the controller, each time the content panel is simply cleared (contentPanel.clear()) and then populated (new viewX(contentPanel);).

eg:
Code:
class MyProgramController {
  private ViewFactory viewFactory; //injected at startup
....
...
..

  public drawViewX() {
    viewFactory.getRootView().getMenuWidget().clear();
    viewFactory.getRootView().getMenuWidget().add(new MenuView(configForX));
    viewFactory.getRootView().getContentWidget().clear();
    viewFactory.getRootView().getContentWidget().add(new viewX());
  }
}

That is highly simplified. The root view in this case would for example, if I take MyBB, the top nav would be the menu and the content panel would be everything below that... Although for myBB I would probably at another panel at the bottom and logo/user panel at the top. So topUserPanel, topNavPanel, contentPanel and bottomNavPanel, or something like that. And each panel is re-created by the controller each time it is needed (only if it changes)..

Hard to explain in words.

Also I have no idea how things run in the .NET world.
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X