I’m trying to make a simple website using mvc but I’m a little confused about how to structure everything. Are there any guidelines for this sort of thing?
What I’m having difficulty with is knowing how to deal with a lot of nested pages, and how to use ViewModels, or rather when
I’ve built a site in MVC before but it was incredibly simple: there was only about 5 pages total so it wasn’t difficult to build. In my current situation, I’m trying to build a site that has a number of nested pages and I wonder how I structure this.
For example, if I had a structure something like this:
Home
|
About -------- Contact---------- Products
|
|
The Board -- What we do
|
|
person1 -- person2 -- person3
How should I set up my site structure?
My gut feeling is that I should have an AboutController, a ContactController and a ProductsController. I’d then have two ActionResults called ‘TheBoard’ and ‘WhatWeDo’ in the AboutController but then how do I handle the nested pages of ‘TheBoard’? What if I had even more pages nested underneath this? Would I have nested Controllers?
Also, even though this dummy site doesn’t require it, what if I wanted to share ViewModels? I’m assuming a ViewModel can be shared across pages (assuming the same functionality is required). Or is this bad practice? Should a new ViewModel be created for each page?
Apologies if I haven’t explained this very well. Basically what I’m looking for is any resources on how to structure an MVC 3 web app that contains a lot of pages. Are there any basic principles that should be followed? I’ve followed most of the tutorials on the asp.net site but there weren’t really any guidelines on best practices.
Any ideas?
Thanks
EDIT: Just to clarify, if I was building this site using webforms, I’d probably have a default.aspx page with About, Contact, Products folders and any nested pages/folders within. I suppose I’m trying to figure out how I’d do this in MVC?
I would have an AboutController, a ContactController, a ProductController as you mention
The AboutController could have an Action Person.
Set up a route in global.asax as follows:
the Person action should look like this:
If the pages are static, just have different views and check the personName and return the relevant view: e.g.
Where BoardMember1.cshtml / aspx is a View within the Views/About Directory