troubleshooting Question

List of years for dropdown list in mvc4

Avatar of RBS
RBS asked on
.NET Programming
2 Comments1 Solution358 ViewsLast Modified:
I'm trying to create a simple list of years for a dropdown list in MVC4.  I can do it by brute force with the following:

            var startYear = 1945;
            var finishYear = 2000;

            var yearList = new List<RegistrationViewModel.Year>
                new RegistrationViewModel.Year {Id = 1950, Name = "1950"},
                new RegistrationViewModel.Year {Id = 1951, Name = "1951"},
                new RegistrationViewModel.Year {Id = 1952, Name = "1952"},
                new RegistrationViewModel.Year {Id = 1953, Name = "1953"},
                new RegistrationViewModel.Year {Id = 1954, Name = "1954"}

However, I'd like to do it with a for (int i = startYear ; i < finishYear+1; i++) loop.

Any assistance for this tired brain in doing this greatly appreciated.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros