Reputation: 2634
In my ASP.NET MVC application I am using a select list control to generate a list for a multiselect widget:
<%=Html.ListBoxFor( m => m.Product.Name,
new SelectList(
Model.Products.Where(
s => !Model.Product.Any(
t => t.Id == s.Id.Value
) ).OrderBy( t => t.Name ), "Id", "Name",
new { multiselect = "multiselect", @class = "fancySelect products"} ) ) %>
Which will generate a list of items. The problem is that some of them need encoding:
<span>Cōnetic™ Technology</span>
If I render this item directly to the UI using a simple response.write I see this:
<p class="c">Cōnetic™ Technology</p>
How would I go about integrating an Html.Encode into my select list statement to produce the same encoding result? Or is there a better encoding method that will effect select lists on a global level?
This is MVC 2 btw, so no razor.
Upvotes: 1
Views: 946
Reputation: 5843
You need to encode data before displaying, and it should render as expected. Here you example which we used in our asp.net mvc2 project:
<%= Html.Encode(ViewData["PasswordLength"]) %>
It is in a namespace System.Web.Mvc, and it converts the specified string to an HTML-encoded string.
Upvotes: 1