Tags : asp-net-mvcrss
This shows how to set a simple RSS Feed template using a strongly-typed Razor view and passing the view a List<Snippet> (but could be any IEnumerable).
<!---View Snippet-->
@{
Response.ContentType = "text/xml";
Layout=null;
}
@model List<Snippet>
<rss version="2.0">
<channel>
<title>@SnippetApp.GlobalSettings.SiteName Feed</title>
<link>@SnippetApp.GlobalSettings.SiteURL </link>
<description>RSS Feed for @SnippetApp.GlobalSettings.SiteName</description>
<language>en-us</language>
@foreach (Snippet snippet in Model)
{
<item>
<title>@snippet.Title</title>
<link>@snippet.FullUrl</link>
<pubDate>@snippet.CreateDate.Value.ToUniversalTime()</pubDate>
<description>@snippet.Description</description>
</item>
}
</channel>
</rss>
<!--Controller Snippet-->
public ActionResult Feed()
{
var snippetList = Snippet.GetSnippets();
return View(snippetList);
}
blog comments powered by Disqus