asp.net - Set Default Date with DropdownListFor using Enumerable Range -


I am trying to set the current date of the dropdown, I have been trying several ways to get it I am .. So this is my sample code.

  @ {var days = Enumerable.Range (1, 31). Select (i = & gt; new selectionlitem {value = i.ToString (), text = i.ToString (), selected = i == date time.Now day}). ToList (); Var Month = Noteworthy Category (1, 12). Select (i = & gt; New SelectionLitem {value = i.ToString (), text = SystemGlobalization.CalcherInfo.InvierientCulture.Dataimform.GetMonthName (i), Selected = i == DateTime.Nowmonth}). ToList (); Var year = exclusive. Select Category (2000, Date Time.N.Y. - 2000 + 4) (i = & gt; New Selection List {value = i.ToString (), Text = i.ToString (), Selected = i == DateTime.Now . year}). ToList (); } @ Html.DropDownListFor (model = & gt; model. Sday, days) @ Html.DropDownListFor (model => model.SMonth, month) @ Html.DropDownListFor (model => model year, year) < / Code> 

As you can see that today, day, month and year set today in the selected option, Debugger tells me that today's day has been chosen, but on Day 1 Is set


Comments