I am trying to implement a method where I select all records that belong to the correct StateId (NJ, DE, PA); I am using dependency injection and the repository design pattern which I am new to.
Here is what I have in my controller:
private IWorkOrderRepository _workOrderRepository;
public DependencyInjectionController(IWorkOrderRepository workOrderRepository)
{
_workOrderRepository = workOrderRepository;
}
public IActionResult WorkOrders()
{
var model = _workOrderRepository.GetWorkOrders();
return View(model);
}
public IActionResult Nj(string LocationFilter)
{
var locations = _workOrderRepository.GetWorkOrders().Select(x => x.StateId == LocationFilter).ToList();
return View(locations);
}
The GetWorkOrders method works exactly as it's supposed to.
Here is my Model:
public class WorkOrderContext : DbContext
{
public DbSet<WorkOrder> WorkOrder { get; set; }
public WorkOrderContext(DbContextOptions<WorkOrderContext> options)
: base(options)
{
}
}
public class WorkOrder
{
[Key]
public int UserId { get; set; }
public string LocationId { get; set; }
public string Reason { get; set; }
public bool IsActive { get; set; } = true;
public DateTime Date { get; set; } = DateTime.Now;
public string StateId { get; set; }
}
The error I am getting when I hit the route is:
"The model item passed into the ViewDataDictionary is of type 'System.Collections.Generic.List
1[System.Boolean]', but this ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IEnumerable1[WorkOrderServices.Models.WorkOrder]'."