views:

16

answers:

1

I wish to encode my HTML sent to the browser. In my .ASPX pages I can use the <%: %> syntax. In a HTML helper of mine I try...

    public static string Image(this HtmlHelper helper, string imageName, string altText)
    {
        return helper.Encode(String.Format("<image src='/images/{0}' alt='{1}' />", imageName, altText));
    }

However, when the HTML reaches the browser the HTML just displays as text and no image is shown. How does one encode their HTML from a helper method?

A: 

remove the "helper.Encode"

public static String MyImg(this HtmlHelper helper, string imageName, string altText) {
   return String.Format("<image src='/images/{0}' alt='{1}' />", imageName, altText);
}
Bugeo