Search code examples
asp.netmodel-view-controllermvvmviewmodel

model passed College.WebInterface.Models.ViewModels.HomeIndexViewModel but instance requires a mdel itm of typ College.WebInterface.Models.Department


Controller code

///Controller
public IActionResult Index() { 
    HomeIndexViewModel HomePageModel = new HomeIndexViewModel();
    //List<Notification> nf = new List<Notification>();
    var f = (from n in _context.Notifications.OrderByDescending(n => n.Date)  select n).Take(5);
    HomePageModel.Notifications.AddRange(f);        
      return View(HomePageModel);
    }

Razor Page code

    ///Razor-View Code 
    @model College.WebInterface.Models.ViewModels.HomeIndexViewModel
    <h1>Welcome </h1>

I am getting this error even after using the correct objects and models. what might be the reason. TIA


Solution

  • resolved the issue in another forum .. there was a reference to College.WebInterface.Models.Department in the main Layout page... after removing that reference it worked perfectly...