Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropdown For next 10 years

what is the best way make a dropdown list in MVC4 (View) that show current year plus next 10 years? Should I make an enum and then include it in my view model and make a variable of that enum type?

like image 623
user2137186 Avatar asked Nov 01 '13 08:11

user2137186


2 Answers

Enumerable.Range(DateTime.Now.Year, 10)

will give you numbers that you can then use in the SelectList() constructor for your DropDownList

like image 71
LINQ2Vodka Avatar answered Oct 03 '22 04:10

LINQ2Vodka


When you use Enum for that it will hard coded .Every end of year you should have to re deploy the solution.So better to use as following code in your business layer and push into view layer then based on server Date every user can retrive the next 10 years.

 IList<int> years= Enumerable.Range(DateTime.Now.Year, 10).ToList();
like image 42
Thilina H Avatar answered Oct 03 '22 04:10

Thilina H