I want to show a ValidationSummary mcv3 with \"alert-error\" Bootstrap styling.
I\'m using a Razor view, and I show model errors with this code:
@Html.V
Consider writing an extension method to the HtmlHelper like:
public static class HtmlHelperExtensions
{
public static HtmlString ValidationSummaryBootstrap(this HtmlHelper htmlHelper)
{
if (htmlHelper == null)
{
throw new ArgumentNullException("htmlHelper");
}
if (htmlHelper.ViewData.ModelState.IsValid)
{
return new HtmlString(string.Empty);
}
return new HtmlString(
""
+ htmlHelper.ValidationSummary()
+ "");
}
}
Then you just need to fit the ul-li styling in your stylesheet.