After running my project visual studio has shown me this System.NotSupportedException in my Index.cshtml
Here's my HomeController
public class HomeController : BaseController
{
public ActionResult Index()
{
var events = this.db.Events
.OrderBy(e => e.StartDateTime)
.Where(e => e.IsPublic)
.Select(e => new EventViewModel()
{
Id = e.Id,
Title = e.Title,
Duration = e.Duration,
Author= e.Author.FullName,
Location = e.Location
});
var upcomingEvents = events.Where(e => e.StartDateTime > DateTime.Now);
var passedEvents = events.Where(e => e.StartDateTime <= DateTime.Now);
return View(new UpcomingPassedEventsViewModel()
{
UpcomingEvents = upcomingEvents,
PassedEvents = passedEvents
});
}
}
}
Here is my EventViewModel.cs
public class EventViewModel
{
public int Id { get; set; }
public string Title { get; set; }
public DateTime StartDateTime { get; set; }
public TimeSpan? Duration { get; set; }
public string Author { get; set; }
public string Location { get; set; }
}
"BugFinder" answered my question. My events doesn't hold StartDateTime. So, here is the answer