I'm following a tutorial where the author inherits from ActionResult to create RssViewResult class that will return RSS. When I run the code and go to the action method that returns RssViewResult as a result the plain XML file appeares. I'm new to RSS and seems like in this tutorial there is no special view that has been created.
Do I need to create a view or I made a mistake in my code?
Here is the code:
public class RssViewResult : ActionResult
{
public RssViewResult(SyndicationFeed feed)
{
RssFeed = feed;
}
public SyndicationFeed RssFeed { get; set; }
public override void ExecuteResult(ControllerContext context)
{
var resp = context.HttpContext.Response;
resp.ContentType = "application/rss+xml";
var rss = new Rss20FeedFormatter(RssFeed);
using (var xml = XmlWriter.Create(resp.Output))
{
rss.WriteTo(xml);
}
}
}
And here is the action method that returns RSS:
public RssViewResult RssFeed()
{
var feed = new SyndicationFeed("News", "Store news",
new Uri(Request.Url.AbsoluteUri))
{
Items = _itemsRepository
.GetItems()
.Select(i =>
new SyndicationItem(
i.Product.Name,
i.Product.Description,
new Uri(Request.Url.AbsoluteUri)))
};
return new RssViewResult(feed);
}