Hi nabilabolo,
Check this example. Now please take its reference and correct your code.
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
DateTime weekEndDate = DateTime.Now.Date.AddDays(7);
int count = GetDateTimes().Where(x => x.Date >= DateTime.Now.Date && x.Date < weekEndDate.Date).Count();
TempData["Count"] = count;
return View();
}
private List<DateTime> GetDateTimes()
{
List<DateTime> dateTimes = new List<DateTime>();
dateTimes.Add(new DateTime(2019, 12, 18));
dateTimes.Add(new DateTime(2019, 12, 19));
dateTimes.Add(new DateTime(2019, 12, 20));
dateTimes.Add(new DateTime(2019, 12, 21));
dateTimes.Add(new DateTime(2019, 12, 21));
dateTimes.Add(new DateTime(2019, 12, 22));
dateTimes.Add(new DateTime(2019, 12, 23));
dateTimes.Add(new DateTime(2019, 12, 23));
dateTimes.Add(new DateTime(2019, 12, 24));
dateTimes.Add(new DateTime(2019, 12, 25));
dateTimes.Add(new DateTime(2019, 12, 26));
dateTimes.Add(new DateTime(2019, 12, 27));
dateTimes.Add(new DateTime(2019, 12, 28));
dateTimes.Add(new DateTime(2019, 12, 29));
dateTimes.Add(new DateTime(2019, 12, 30));
dateTimes.Add(new DateTime(2019, 12, 31));
return dateTimes;
}
}
View
Count : <b><%=TempData["Count"].ToString()%></b>
Output
Count : 2