Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:56:31+00:00 2026-06-09T15:56:31+00:00

ViewModel for allSundaysInMonth, I kept this the same: namespace TradeUK.Admin.Web.ViewModels { public class SundaysInMonthViewModel

  • 0

ViewModel for allSundaysInMonth, I kept this the same:

  namespace TradeUK.Admin.Web.ViewModels
  {
      public class SundaysInMonthViewModel
      {
         public IEnumerable<SelectListItem> AllSundays { set; get; }
         public string SelectedSunday { set; get; }
      }
  }

Then in my action the new code:

public ActionResult TradeUKKPISearchesData() //show dropdownlist in the view
{
  var now = DateTime.Now;
  var lastMonth = now.AddMonths(-1);
  var lastMonthSundays = GetDatesOfSundays(lastMonth.Year, lastMonth.Month);
  var thisMonthSundays = GetDatesOfSundays(now.Year, now.Month);
  var sundaysToTakeFromLastMonth = 2;
  var sundays = lastMonthSundays.Skip(Math.Max(0, lastMonthSundays.Count() - sundaysToTakeFromLastMonth)).Take(sundaysToTakeFromLastMonth).Concat(thisMonthSundays);

  var allSundaysInThisMonth = new SundaysInMonthViewModel
  {
    AllSundays = sundays.Select(x => new SelectListItem
    {
      Value = x.ToString("dd-MM-yyyy"),
      Text = x.ToString("dd-MM-yyyy"),
    });

    //or must I have the code here? not sure how all this works yet
    SelectedSunday = sundays.Select(y => new SelectListItem
    {
      Value = 
      Text = 
    }) 
  };

  //this is what I meant or can I add this to the above?
  var selectedSunday = new SundaysInMonthViewModel{
    SelectedSunday = sundays.Select(y => new SelectListItem
    {
      Value = 
    })
  }
  return View(allSundaysInThisMonth);
}

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:56:32+00:00Added an answer on June 9, 2026 at 3:56 pm
    public IEnumerable<DateTime> GetDatesOfSundays(int year, int month)
    {
        var ci = CultureInfo.InvariantCulture;
        for (int i = 1; i <= ci.Calendar.GetDaysInMonth(year, month); i++)
        {
            var date = new DateTime(year, month, i);
            if (date.DayOfWeek == DayOfWeek.Sunday)
            {
                yield return date;
            }
        }
    }
    

    and then in your controller:

    public ActionResult TradeUKKPISearchesData()
    {
        var now = DateTime.Now;
        var lastMonth = now.AddMonths(-1);
        var lastMonthSundays = GetDatesOfSundays(lastMonth.Year, lastMonth.Month);
        var thisMonthSundays = GetDatesOfSundays(now.Year, now.Month);
        var sundaysToTakeFromLastMonth = 2;
        var sundays = lastMonthSundays
            .Skip(Math.Max(0, lastMonthSundays.Count() - sundaysToTakeFromLastMonth))
            .Take(sundaysToTakeFromLastMonth)
            .Concat(thisMonthSundays);
    
        var allSundaysInThisMonth = new SundaysInMonthViewModel
        {
            AllSundays = sundays.Select(x => new SelectListItem
            {
                // TODO: Adjust the formats you want for the 
                // Value and Text of your ddl
                Value = x.ToString("yyyy-MM-dd"),
                Text = x.ToString("yyyy-MM-dd"),
            }),
            SelectedSunday = thisMonthSundays
                .Where(x => x < now)
                .Last()
                .ToString("yyyy-MM-dd")
        };
        return View(allSundaysInThisMonth);
    }
    

    and in your view:

    @model SundaysInMonthViewModel
    ...
    @Html.DropDownListFor(x => x.SelectedSunday, Model.AllSundays)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this ViewModel public class CustomerSuscribeViewModel : IValidatableObject { [DataMember(IsRequired = true)] [DataType(DataType.Text)]
My ViewModel looks like this: public class DirectoryViewModel : ViewModelBase { public ObservableCollection<DirectoryViewModel> SubDirectoryList
I created this viewmodel: public class PlayerViewModel { PlayerRepository repo = new PlayerRepository(); public
This is my ViewModel: public class PlayerViewModel { PlayerRepository repo = new PlayerRepository(); public
PagesCollection.ViewModel.PagePictureCommands.cs namespace PagesCollection.ViewModel { public partial class PagePicturesViewModel : IPropertieCommands { private ICommand deleteAlbum;
If I had a viewmodel that looked something like this public class AddressViewModel {
If i have a ViewModel like this: public class MyViewModel { [UIHint(SomeTemplate)] public ICollection<SomeViewModel>
If i have a ViewModel like this: public class SignupViewModel { [Required] [DisplayName(Email:)] public
We have a ViewModel with a collection of Widget<dynamic> : public class Widget<T> {
My ViewModel: class ViewModel { public string FileName {get;set;} } and in my View

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.