I call a model in view.cshtml like this:
@model IEnumerable<Spiirit_Project.Models.Deliverable>
Then I use this LINQ-method in view.cshtml so:
@{ var a = Model.Where(p => p.deliverable_research_year_id == 169).Count(); }
When I run my project, there is error: "Value cannot be null. Parameter name: source".
my "Deliverable" Table is not null but I get this error. How to fix this error?
there is my controller:
public ActionResult CreateDeliverable(int? idResearch, int? idBaseline, int? idYear){
ViewBag.IdResearch = idResearch;
ViewBag.IdBaseline = idBaseline;
ViewBag.IdYear = idYear;
ViewBag.Year = db.Deliverable_Research_Years.Find(idYear);
ViewBag.Deliverable = db.Deliverables.ToList();
return View();
}
return View(db.Deliverables.ToList());- and no need to assign toViewBag.Deliverable. Then have a read of stackoverflow.com/questions/6242810/why-is-the-view-model-null .ModelthanViewBag- stackoverflow.com/questions/21716953/…ViewBag. Read the link I provided. If you need multiple objects, then create your ownAghnatModelclass with multiple properties (for each of things you need). Then use@model Spiirit_Project.Models.AghnatModel.