View models in an MVC context are usually expected to be POCOs and just act as some kind of a data transfer object between the controller and the view. As such, they should rarely contain any logic, and definitely not require some external dependencies like your database context.
Instead, you should consider having something else that is responsible of consuming your database context to create a view model. This could be some service class, or just direct logic within the controller action.
This could for example look like this:
public class ExampleController : Controller
{
private readonly DataContext _db;
public ExampleController(DataContext db)
{
_db = db;
}
public async Task<IActionResult> Index()
{
var items = await _db.Items.Where(i => i.State == ItemState.Active).ToArrayAsync();
var vm = new IndexViewModel
{
Items = items,
Date = DateTime.Today,
};
return View(vm);
}
}