5

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?

asked Sep 6, 2012 at 19:08
2
  • well it's a new paradigm for me so I'm trying to get into the right frame of mind for it. Commented Sep 6, 2012 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. Commented Sep 6, 2012 at 20:41

2 Answers 2

3

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.

answered Sep 6, 2012 at 19:12
1

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.

answered Sep 6, 2012 at 20:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.