ASP.NET MVC 4 and Razor 2: View engine no longer supports xml?

liaiskivinatt

New Member
We had a view (.cshtml) which rendered XML for an RSS feed using ASP.NET MVC 3, which worked fine. Now that we have upgraded to ASP.NET MVC 4 with Razor 2 it's generating compile errors, similar to the below.\[code\]Parser ErrorDescription: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.Parser Error Message: Encountered end tag "item" with no matching start tag. Are your start/end tags properly balanced?\[/code\]The tags are properly balanced.Anyone have any thoughts?UPDATE: I've isolated it down the the link element within the item element within the @foreach (...) { ... } block.\[code\]@foreach (var item in Model.Items){<item> <title>@item.Title</title> <link>@item.Link</link> <description>@item.Description</description> <guid>@item.Guid</guid> @if (item.PublishedDateUtc.HasValue) { <pubDate>@item.PublishedDateUtc.Value.ToString("ddd, dd MMM yyyy HH:mm:ss") GMT</pubDate> } </item> }\[/code\]I fixed it by doing using @Html.Raw the below.\[code\]@foreach (var item in Model.Items){<item> <title>@item.Title</title> @Html.Raw(string.Format("<link>{0}</link>", item.Link.ToHtmlEncoded())) <description>@item.Description</description> <guid>@item.Guid</guid> @if (item.PublishedDateUtc.HasValue) { <pubDate>@item.PublishedDateUtc.Value.ToString("ddd, dd MMM yyyy HH:mm:ss") GMT</pubDate> } </item> }\[/code\]Anyone have any better suggestions? Obviously, I could just use a class to declare model and return the XML directly from the controller, but I'm more interested in why this behavior occurs and what I can do to conform better to the Razor syntax.
 
Back
Top