I have a controller that contains a LINQ query. My query looks something like the following:
var posts = GetBlogPosts();
var results = from post in posts
select new
{
Title = "This is the blog title",
Url = "www.google.com",
Author = "Bill Jones",
AuthorUrl = "www.billjones.com",
Description = "This is the description of the post"
};
ViewBag.Posts = results;
I am trying to display the Posts in my view. Currently, I have the following:
@foreach (var post in ViewBag.Posts)
{
<div class="postBody">
<h1 class="blogTitle">@post.Title</h1>
<p class="blogInfo">@post.Description</p>
</div>
}
When I execute this, I receive an error at runtime. My error says:
'object' does not contain a definition for 'Title'
What am I doing wrong?