Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert Bullock 15 posts 75 karma points
    Aug 02, 2021 @ 16:40
    Robert Bullock
    0

    Html.If UrlEncoded

    It's great we have the Html.If helper extension, but why does it return an encoded value when you have a true/false value and not encoded when there's only a true value? It's really messing up my templates.

        public static IHtmlString If(this HtmlHelper html, bool test, string valueIfTrue)
        {
            return If(html, test, valueIfTrue, string.Empty);
        }
    
        /// <summary>
        /// If <paramref name="test" /> is <c>true</c>, the HTML encoded <paramref name="valueIfTrue" /> will be returned; otherwise, <paramref name="valueIfFalse" />.
        /// </summary>
        /// <param name="html">The HTML helper.</param>
        /// <param name="test">If set to <c>true</c> returns <paramref name="valueIfTrue" />; otherwise, <paramref name="valueIfFalse" />.</param>
        /// <param name="valueIfTrue">The value if <c>true</c>.</param>
        /// <param name="valueIfFalse">The value if <c>false</c>.</param>
        /// <returns>
        /// The HTML encoded value.
        /// </returns>
        public static IHtmlString If(this HtmlHelper html, bool test, string valueIfTrue, string valueIfFalse)
        {
            return new HtmlString(HttpUtility.HtmlEncode(test ? valueIfTrue : valueIfFalse));
        }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies