allSundaysInMonthのViewModel、私はこれを同じに保ちました:
namespace TradeUK.Admin.Web.ViewModels
{
public class SundaysInMonthViewModel
{
public IEnumerable<SelectListItem> AllSundays { set; get; }
public string SelectedSunday { set; get; }
}
}
次に、私のアクションで新しいコード:
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);
}
ありがとう