Reputation: 3707
I have a controller that passes data to my view through the ViewBag
My controller:
var aJobs = from a in gdb.AcceptedJobs
where a.Job.EmployerID == (Guid)Session["UserID"] && !a.Archived
select new { a.Job.Title, a.Job.Address };
ViewBag.jobs = aJobs;
return View("Employer");
My view:
foreach (var job in ViewBag.jobs)
{
@job.Title
@job.Address
}
Now, when i browse to the page i get error object does not contain a definition for Title
, at @job.Title
, why is this?
I'm using ASP.Net MVC3 C#
Upvotes: 0
Views: 1512
Reputation: 3707
When im debugging, and the error is thrown i checked the locals. Then i can clearly see that in the first iteration, the job-object contains a Title-string with the value of my name.
Upvotes: 0
Reputation: 190976
Try creating your anonymous type this way
select new { Title = a.Job.Title, Address = a.Job.Address };
Upvotes: 2