MVC 3 Display HTML inside a ValidationSummary

前端 未结 5 1589
遥遥无期
遥遥无期 2021-02-14 14:18

I am trying to display a strong tag inside a validation summary but it encodes it and does not display properly.

@Html.ValidationSummary(false, \"E         


        
5条回答
  •  無奈伤痛
    2021-02-14 15:09

    I've find this :

        public static MvcHtmlString ToMvcHtmlString(this MvcHtmlString htmlString)
        {
            if (htmlString != null)
            {
                return new MvcHtmlString(HttpUtility.HtmlDecode(htmlString.ToString()));
            }
            return null;
        }
    

    and then :

    @Html.ValidationSummary(false, "ERROR:The form is not valid!").ToMvcHtmlString()
    

提交回复
热议问题