これを試して;
private const int PostsPerFeed = 25; //Change this to whatever number you want
次に、あなたの行動:
public ActionResult Rss()
{
IEnumerable<SyndicationItem> posts =
(from post in model.Posts
where post.PostDate < DateTime.Now
orderby post.PostDate descending
select post).Take(PostsPerFeed).ToList().Select(x => GetSyndicationItem(x));
SyndicationFeed feed = new SyndicationFeed("John Doh", "John Doh", new Uri("http://localhost"), posts);
Rss20FeedFormatter formattedFeed = new Rss20FeedFormatter(feed);
return new FeedResult(formattedFeed);
}
private SyndicationItem GetSyndicationItem(Post post)
{
return new SyndicationItem(post.Title, post.Body, new Uri("http://localhost/posts/details/" + post.PostId));
}
FeedResult.csで
class FeedResult : ActionResult
{
private SyndicationFeedFormatter formattedFeed;
public FeedResult(SyndicationFeedFormatter formattedFeed)
{
this.formattedFeed = formattedFeed;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "application/rss+xml";
using (XmlWriter writer = XmlWriter.Create(context.HttpContext.Response.Output))
{
formattedFeed.WriteTo(writer);
}
}
}
デモストレーションはこちらです。警告ですが、グーグルクロームのフォーマットはまだありません