Skip to content Skip to sidebar Skip to footer

MVC.net 2 - Change The HTML Outputed By ValidationMessageFor - Can This Be Down Via Templates?

MVC.net 2 by default outputs validation messages like this: A Validation message I would li

Solution 1:

The code that generates that html is inside of ValidateExtensions.cs, in System.Web.Mvc. You could update the code to output a label instead of a span and then recompile that. The code looks like the following:

        TagBuilder builder = new TagBuilder("span");
        builder.MergeAttributes(htmlAttributes);
        builder.MergeAttribute("class", HtmlHelper.ValidationMessageCssClassName);
        builder.SetInnerText(String.IsNullOrEmpty(validationMessage) ? GetUserErrorMessageOrDefault(htmlHelper.ViewContext.HttpContext, modelError, modelState) : validationMessage);

Otherwise, you might be able to override ValidationExtensions.ValidationSummary(this HtmlHelper htmlHelper, string message, IDictionary htmlAttributes) and do it that way...


Solution 2:


Post a Comment for "MVC.net 2 - Change The HTML Outputed By ValidationMessageFor - Can This Be Down Via Templates?"