I know that to generate rss I can use built-in classes like SyndicationFeed and Rss20FeedFormatter. Also I know that it can be done with custom classes and aspx view.
But if I want to create custom feed objects and custom view, can I do this using razor?
Here is my view:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<h2>@Model.Title</h2>
<div><b>Description:</b> @Model.Description</div>
<div><b>Language:</b> @Model.Language</div>
<a href="@Model.Url" class="averageLink">Subscribe to this Feed</a>
@foreach (var item in Model.Items)
{
<h3>
Title: @item.Title
</h3>
<div>
<img width="75" height="75" src="@Url.Action("GetImage", "Store", new { productId = item.ProductId })"/>
</div>
<div><b>Description:</b> @item.Description</div>
<div><b>Creator:</b> @item.Creator</div>
<div><b>Date published</b> @item.Published</div>
<div>
<a href="@item.Url" class="averageLink">place order on Ozon</a>
</div>
@Html.ActionLink("go to item", "ItemInformation", "Store", new {itemId = item.ItemId}, new {@class = "averageLink"})
}
</channel>
</rss>
Other questions:
1) I don’t know how exactly to implement “subscription” link: what value to assign to the @Model.Url?
2) It generates html, mabby instead I need to serialize my feed objects into xml document and return it with a custom XmlResult : ActionResult?
Edit 1: Mabby I somehow can use built-in classes and custom feed model together?
Edit 2: The reason I don’t want to use the existing classes is because I need to use Html.ActionLink() and Url.Action() helpers. If I serialize feed object into xml how would I use these helper methods?
Thanks for help in advance!
Your view code is producing html, not the xml that is needed for an rss feed (you are including elements like
divandh3that are part of html).To produce a view that outputs RSS, the layout of the view should replicate the RSS standard.
For example:
However, you may want to consider a different approach: returning a result from your Controller Action that will generate the RSS directly. You can see examples of this approach in this blog post or described in this answer.