C# ASP.NET MVC Forms Improving Our Form Completing the “Activity” Field Drop Down List

Aren'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
Richard Verbraak
7,712 Points

I'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.