Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm starting with MVC and have a newbie question. What would be the logic criteria to define what a controller should encompass? For example, say a website has a 'help' section. In there, there are several options like: 'about us', 'return instructions', 'contact us', 'employment opportunities'. Each would then be accessed like 'mysite.com/help/aboutus', 'mysite.com/help/returns', 'mysite.com/help/contactus', etc.

My question is, should I have a 'help' controller that has 'about us', 'returns', 'contact us', 'employment' as actions with their respective view, or should each of those be a different controller-action-view set? What should be the line of reasoning to determine when to separate controllers?

share|improve this question
    
well it's a new paradigm for me so I'm trying to get into the right frame of mind for it. –  Rodolfo Sep 6 '12 at 19:27
    
The most web-friendly definition of MVC I have seen is that used by Ruby on Rails. Check out what they do. –  GlenPeterson Sep 6 '12 at 20:41
add comment

2 Answers

up vote 3 down vote accepted

That is entirely up to you.

With ASP.Net MVC3 you can choose if you want the default routing to do the work, or if you want to manually create some sexy URLs. You can create routes that look to be within the same controller but they can in fact be in many different controllers.

The criteria you should use when deciding the organization of Controllers and their method is, are these actions related in some way?

Following your example for Help. It would make sense to keep them within the same controller because they do offer "Help" in one way or another.

share|improve this answer
add comment

Typically a controller maps a class to a base URL, usually a webpage e.g. mysite.com/help, so you have the right idea. The class methods are typically handlers for actions triggered by controls on the page - which typically have an appended path e.g. mysite.com/help/contact - if say 'contact' were a button that opened the user's default mail program w/ the company's address populated in the 'To' field.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.