There's an overload for HtmlHelper.AttributeEncode(object) that converts the input to a string, and then calls HtmlAttributeEncode -- this prevents correct processing of a pre-encoded object that implements IHtmlString.
This is likely the case because there's an existing function HttpUtility.HtmlEncode(object), but no corresponding overload HttpUtility.HtmlAttributeEncode(object).
This is likely the case because there's an existing function HttpUtility.HtmlEncode(object), but no corresponding overload HttpUtility.HtmlAttributeEncode(object).