0

The Project: I have several cases where I'm not sure whether or not I should be using a 'Separation of Concerns' approach or a simplistic one. They're all similar to the setup below.

e.g. An Estimate contains multiple Notes

EstimateController.Details -> Displays the details of an Estimate (Name, Description, Etc.) and below that it displays a tabular view of Notes (separated by type).

My Thoughts:

On one hand, it would be a separation of concerns and creating a new controller sounds like the proper way to do things, making use of partial views if necessary.

On the other hand, it seems a bit like overkill to have a controller for all the cases like this. (i.e. Estimates contain: Notes, Specification Numbers, Drawing Numbers, and Addendums. This is similar to multiple other models in the business model as well).

Question:

  • How trivial is to trivial to justify creating a separate controller for an sub-model?

I've found many places saying that you should have a separate controller for each view model but out of the ones I've seen none of them mention why or mention how trivial of a model is too trivial?

  • 1
    How many methods will your new controller have? Is there any benefit of promoting reusability? – Robert Harvey Sep 10 '14 at 15:47
  • Well, there's the delete and I could pull some of the view into a partial view action (not sure if that'd be the best way to do it though). So 2, maybe 3? I'm also using Entity Framework, I'm not sure if that affects anything though. – Shelby115 Sep 10 '14 at 15:48
  • Does the new controller have a collection of independent URLS that corresponds to it, such as http://mysite/Notes/Details/236? Or is it http://mysite/Estimate/Notes/Details/236? – Robert Harvey Sep 10 '14 at 15:50
  • I could but generally speaking they won't. I was planning on having most of it handled on one or two pages pertaining to Estimate so like http://localhost:#####/Estimates/Details/1 They'll be deleted using AJAX and a simple button next to the note/item. I've implemented other things (creation, display) without question but deletion feels different. – Shelby115 Sep 10 '14 at 15:56
  • Then you don't need another controller. You just need a ViewModel and a View (or composite view) that handles the notes. If the Ajax gets complicated enough to warrant another controller, then by all means do so. But I would expect to see all that stuff in the same place unless you're building a service to do the AJAX (an entirely reasonable approach). – Robert Harvey Sep 10 '14 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.