I have an html helper which takes in a broken address and formats it, but i’m seeing the actual <br /> tag as text instead of a line break on my web page.
What am i doing that’s causing this to occur?
Here’s part of my helper method
public static HtmlFormatAddress(this helper, string number
, string fraction
, string direction
, string street
, string type
....)
{
var sb = new StringBuilder();
if (!string.IsNullOrEmpty(number))
sb.Append(number.Trim() + " ");
if (!string.IsNullOrEmpty(fraction))
sb.Append(fraction.Trim() + " ");
if (!string.IsNullOrEmpty(direction))
sb.Append(direction.Trim() + " ");
if (!string.IsNullOrEmpty(street))
sb.Append(street + " ");
if (!string.IsNullOrEmpty(type))
if (sb.Length > 0)
sb.Append("<br />");
.....
return sb.ToString();
}
If this is MVC2/ASP.NET 4, you need to return an
MvcHtmlStringinstead ofStringIf not, then be sure you are not encoding the output with
<%: %>but instead use<%= %>