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:

TagBuilderbuilder=newTagBuilder("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:

I think this is exactly what you're looking for:

http://blog.syntaxc4.net/?p=711

Post a Comment for "Mvc.net 2 - Change The Html Outputed By Validationmessagefor - Can This Be Down Via Templates?"