Select Date using 3 drop-down lists (day / month / year) in ASP.NET MVC

I am using ASP.NET MVC with WEB API.

I need to tell the user to enter his date of birth, the entrance should be 3 drops

  • Choose day
  • Choose month and
  • Choose year

I can fill out the dropdown lists using the following code ...

@Html.DropDownList("month", Enumerable.Range(1, 12).Select(i => new SelectListItem { Value = i.ToString(), Text = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(i)}), "-- Month --") @Html.DropDownList("day", Enumerable.Range(1, 31).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString()}), "-- Day --") @Html.DropDownList("year", Enumerable.Range(1920, DateTime.Now.Year).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString()}), "-- Year --") 

However, I still have to write custom js or C # code to make sure, for example: February is not more than 28 days for a certain year, etc. etc.

Is there any other method that you can suggest, please ... Please share your thoughts on this.

EDIT : I do not use JQuery Date Picker, since by my requirement I should have 3 drop downs for day, month and year, somewhere else in the application for the rest of the date picker I used JQuery DatePicker.

+3
source share
2 answers

It is necessary to update the drop-down list of days when changing the drop-down list of the month and load the days in accordance with the selected month

0
source

This is definitely a good use case for datepicker, for example from jQuery UI !

Edit:

Given your new requirement, you should take a look at How to populate each other's cascading drop-down list using jquery in mvc 3?

-2
source

All Articles