We had a view (.cshtml) that displayed XML for the RSS feed using ASP.NET MVC 3, which worked fine. Now that we have upgraded ASP.NET MVC 4 using Razor 2, it generates compilation errors similar to the ones below.
Parser Error Description: 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?
Tags are correctly balanced.
Anyone have any thoughts?
UPDATE: I highlighted it using the link element inside the item element in @foreach (...) {...}.
@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> }
I fixed it using @ Html.Raw below.
@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> }
Does anyone have any better suggestions? Obviously, I could just use the class to declare the model and return the XML directly from the controller, but I'm more interested in why this happens and what I can do to better match the Razor syntax.
source share