I have a VERY simple view on my MVC2 application that is responsible for displaying results from a Lucene search; one of whose properties includes the search item’s summary.
At the moment, I’ve resorted to using new HtmlString(myString) as shown below:
<ul>
<% foreach (var Item in Model)
{ %>
<li>
<h4><%: Item.Title %></h4>
<p><%: new HtmlString(Item.Summary) %></p>
<a href="<%: Item.Url %>"><%: Item.Url %></a>
</li>
<% } %>
</ul>
What I’d feel happier about using is
<ul>
<% foreach (var Item in Model)
{ %>
<li>
<h4><%: Item.Title %></h4>
<p><%: Html.Raw(Item.Summary) %></p>
<a href="<%: Item.Url %>"><%: Item.Url %></a>
</li>
<% } %>
</ul>
However whenever I use Html.Raw(myString), I get an HttpCompileException with the following detais:
‘System.Web.Mvc.HtmlHelper>’
does not contain a definition for
‘Raw’ and no extension method ‘Raw’
accepting a first argument of type
‘System.Web.Mvc.HtmlHelper>’
could be found (are you missing a
using directive or an assembly
reference?)
What could be the cause of the problem?
Html.Rawis new in ASP.NET MVC 3 (source: ScottGu), so you won’t be able to use it in ASP.NET MVC 2.