Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialrichardking4
2,997 PointsAren't we violating 'DRY' here?
The relevant part of the video is from 0:50 to 1:12.
James has us copy and paste this line of code from the 'Add' action method into the POST version of our 'Add' method:
ViewBag.ActivitiesSelectListItems = new SelectList(Data.Data.Activities, "Id", "Name");
We're creating a new SelectList item for the purpose of creating a drop-down list in our view β is there not a cleaner, less repetitive way to accomplish this?
1 Answer
Richard Verbraak
7,739 PointsI'm not familiar with the challenge but quite a lot of the videos will not use the DRY method. I think this is done on purpose so you can see the "long" and explicitly typed version of the code that is then refactored later on in the course.
For example: Look it's typed like this but you can also shorthand it like that.