2
Answers

Creating Full calendar

Photo of Anu

Anu

1y
483
1

Hi ,

Please suggest a way to display complete calendar for a year using asp.net MVC. I dont want a scheduler. Instead of scheduler, I want to select multiple days from the displayed calendar to save the selected dates to database as holiday for that year.

Answers (2)

2
Photo of Ajay Kumar
54 29.6k 1.8m 1y

In This Function, You Have to Pass The Year And Get The  Full Year Calender.  

private List<Tuple<DateTime, string>> GenerateCalendarData(int year)
        {
            List<Tuple<DateTime, string>> calendarData = new List<Tuple<DateTime, string>>();

            // Loop through each month of the year.
            for (int month = 1; month <= 12; month++)
            {
                // Calculate the days in the current month.
                int daysInMonth = DateTime.DaysInMonth(year, month);

                // Loop through each day in the month and add it to the list.
                for (int day = 1; day <= daysInMonth; day++)
                {
                    DateTime date = new DateTime(year, month, day);
                    string dayName = date.ToString("dddd"); // Get the day name.

                    calendarData.Add(new Tuple<DateTime, string>(date, dayName));
                }
            }

            return calendarData;
        }
1
Photo of Saravanan Ganesan
36 35.3k 283.3k 1y

To display a complete calendar for a year in an ASP.NET MVC application and allow users to select multiple days to save as holidays, you can follow these steps:

  1. Create a Model: Define a model that represents the selected holidays. This model should include properties for the year and a collection of selected dates.

  2. Create a View: Design a view that displays a calendar for the entire year. You can use HTML tables or a JavaScript library like FullCalendar for this purpose.

  3. Populate the Calendar: In the view, dynamically generate the calendar by iterating through the months and days of the selected year. Style the calendar to highlight weekends and other relevant details.

  4. Select Dates: Implement JavaScript to allow users to select multiple dates on the calendar. Highlight selected dates visually.

  5. Submit Selected Dates: When the user submits the selected dates, send them to the server using an AJAX request or a form submission.

  6. Server-Side Handling: In the controller, handle the selected dates and save them as holidays in the database, associating them with the specified year.

  7. Display Holidays: Optionally, you can create another view to display the holidays for the selected year, allowing users to edit or delete them.