views:

27

answers:

1

Hello,

this question is not about code, at least not about code that gives errors. I am asking this question to know the right way of implementing a pattern in ASP.NET MVC2.

Suppose that I have A Contact object that holds a collection of EmailAddress object. In My ContactController I have regularly actions that do create/edit/delete contacts from the underlying store. Inside my Index View (that render all the contacts) I have a link that says "Add Email" when a Contact is selected in the list.

Now I have at least two ways to implement this Action:

  1. Inside the ContactController add a AddEmailAddress action that pre-populate the EmailAddress Model object with the ContactID property and render a view
  2. As in the step 1 but instead of rendering a view delegate this job to a EmailAddressController class

Which is the correct way to handle patterns like this one?

Thanks in advance!

+1  A: 

I like #1 better. Unless there is a big need for working with Emails separately outside the context of the Contact they go with, I think that's the way to go.

But if you're going to have List Emails, Delete an Email, Create an Email, Edit an Email, etc. screens, then having it's own controller would make more sense. In that case, I would have the hyperlink browse to the email controller and the create action with the contact id as an argument in the URL.

Joe Wilson
@Joe: you're right. I have the requirements to support email handling so I did choose the 2nd way. Thanks for your opinion!
Lorenzo