【发布时间】:2014-02-02 19:28:27
【问题描述】:
我有一个包含 LINQ 查询的控制器。我的查询如下所示:
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;
我正在尝试在我的视图中显示帖子。目前,我有以下内容:
@foreach (var post in ViewBag.Posts)
{
<div class="postBody">
<h1 class="blogTitle">@post.Title</h1>
<p class="blogInfo">@post.Description</p>
</div>
}
执行此操作时,我在运行时收到错误消息。我的错误说:
'object' does not contain a definition for 'Title'
我做错了什么?
【问题讨论】:
标签: c# asp.net-mvc linq