Hi everybody,

I have this:

The view: Index.cshtml

[code]
@model ManyToMany.ViewModels.ProjectIndexData
@{
  ViewBag.Title = "Hours";
}

Hours




  @Html.ActionLink("Create New", "Create")


 
 
 
 
   
 
 

@foreach (var item in Model.Hours) {
 
 
 
 
 
 
 
 
}

ProjectActivity

  @Html.DisplayFor(modelItem => item.Activity.Project.Name) 
 

 
  @Html.DisplayFor(modelItem => item.Activity.Name)
 

  @Html.ActionImage("Edit", new {id = item.HourID},"~/Content/Images/Edit2.png", "Edit" )
  @Html.ActionImage("Details", new{id = item.HourID}, "~/Content/Images/details_icon.gif", "Details")
  @Html.ActionImage("Delete", new{id = item.HourID}, "~/Content/Images/Delete.png", "Delete")
 


[/code]

and the Controller:
HourController:

[code]
 public ActionResult Index(Int32? id)
  {
 
  var viewModel = new ProjectIndexData();
  ViewBag.Projects = db.Projects.ToList();
  ViewBag.Activities = db.Activities.ToList();
  //ViewBag.Hours = db.Hours.ToList();
  //ViewBag.HourID = id.Value;
  var Hours = db.Hours.Include(a => a.Activity).Include(a => a.Activity.Project);
  return View(viewModel);


  }//end method Index
[/code]

and the ProjectIndexData looks like this:

[code]
 public class ProjectIndexData
  {
  public IEnumerable Projects { get; set; }
  public IEnumerable Employees { get; set; }
  public IEnumerable Activities { get; set; }
  public IEnumerable Hours { get; set; }
  public Activity Activity { get; set; }

  }
[/code]

but I get thsi error:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 18: Line 19: @foreach (var item in Model.Hours) { Line 20: Line 21:
Line 17:

Source File: f:\WinituProjects21-07-2012\winituProjects08-07-2012\ManyToMany26-05-2012WorkingVersionWorkingVersion03 - Copy\ManyToMany\Views\Hour\Index.cshtml   Line: 19

THX for helping

Can annybody help me??

THX!!