运行我的项目后,Visual Studio 在我的 Index.cshtml 中向我展示了这个 System.NotSupportedException
这是我的 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
});
}
}
}
这是我的 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; }
}