views:

40

answers:

1

I am using ASP.Net MVC but this probably applies to all MVC patterns in general. My problem, for example I have companies and in each company I have a list of contacts. When I have selected a company I can see its details and a list of the contacts for that company. When I want to add a new contact for that company, should the implementation of that action go into the company controller as an "AddContact" action or should it go into the contact controller into a "New" action and we pass the Company ID in the URL?

What is the usual way of dealing with this sort of thing in ASP.Net MVC? Is there a better stategy?

+2  A: 

In a RESTful application this should go to the New action of the ContactsController. You need to pass the company id as well to this action.

Darin Dimitrov
Thanks for the answer. I am not so sure how REST fits into the picture with MVC. Doesn't REST have all sorts of verbs like GET, POST, DELETE, PUT etc etc. So does MVC address a portion of this? Is MVC meant to fit into a such a scheme or implement the entire scheme?
uriDium
REST and MVC are different in nature. REST is about resources and verbs, while MVC is about separation of concerns. You can do REST with MVC. You can have GET,POST,DELETE and PUT verbs on your MVC controller actions. You can organize your controllers by resources used in your application. You can have actions in your controller such as New, Delete, Create, Index. So to summarize: you can do REST with an ASP.NET MVC application. You will just need to identify resources used by the application and organize your controllers accordingly.
Darin Dimitrov