twitter.bootstrap.mvc
twitter.bootstrap.mvc copied to clipboard
ValidationSummary not rendered in Bootstrap styling
I am using @Html.ValidationSummary(true) but it is rendering in its default div/ul/li styling.
I don't have any integration with LESS yet, so the solution at http://stackoverflow.com/questions/13867307/show-validationsummary-mvc33-as-alert-error-bootstrap is a good option for me ATM.
I have added a partial view as indicated in the SO link.
@if (ViewData.ModelState[""] != null && ViewData.ModelState[""].Errors.Any())
{
<div class="alert alert-error">
<a class="close" data-dismiss="alert">×</a>
@Html.ValidationSummary(true)
</div>
}
I then added this partial view in the bootstrap layout file under the reference to
@Html.Partial("_alerts")
@Html.Partial("ValidationSummary")
The only thing missing is the styling of the UL which I removed with the following css:
.validation-summary-errors ul
{
list-style-type: none;
}
It would be nice if this made it into the package. Not sure how you would want to integrated it though.
Cheers,
Rory
That makes a lot of sense... I need to try this out with the runtime scaffolding.
Eric Hexter
blog | http://Hex.LosTechies.com info | http://www.linkedin.com/in/erichexter
On Sat, Dec 29, 2012 at 5:05 AM, roryprimrose [email protected]:
I am using @Html.ValidationSummary(true) but it is rendering in its default div/ul/li styling.
I don't have any integration with LESS yet, so the solution at http://stackoverflow.com/questions/13867307/show-validationsummary-mvc33-as-alert-error-bootstrapis a good option for me ATM.
I have added a partial view as indicated in the SO link.
@if (ViewData.ModelState[""] != null && ViewData.ModelState[""].Errors.Any()) {
× @Html.ValidationSummary(true)}I then added this partial view in the bootstrap layout file under the reference to
@Html.Partial("_alerts") @Html.Partial("ValidationSummary")
The only thing missing is the styling of the UL which I removed with the following css:
.validation-summary-errors ul{ list-style-type: none;}
It would be nice if this made it into the package. Not sure how you would want to integrated it though.
Cheers,
Rory
— Reply to this email directly or view it on GitHubhttps://github.com/erichexter/twitter.bootstrap.mvc/issues/45.
I started implementing this.. it will need an additional css file to be included in the package, to handle the override of the mvc default style.
Fixed bug in the partial view which wouldn't render errors related to properties (via the true parameter on ValidationSummary)
I now use:
@if (ViewData.ModelState.Any(x => x.Value.Errors.Any()))