I want to show ValidationSummary mcv3 with Bootstrap style "alert-error".
I am using the Razor view and I am showing model errors with this code:
@Html.ValidationSummary(true, "Errors: ")
It generates HTML code as follows:
<div class="validation-summary-errors"> <span>Errors:</span> <ul> <li>Error 1</li> <li>Error 2</li> <li>Error 3</li> </ul> </div>
I also tried:
@Html.ValidationSummary(true, "Errors:", new { @class = "alert alert-error" })
and it works fine, but without a close button (X)
It generates HTML code as follows:
<div class="validation-summary-errors alert alert-error"> <span>Errors:</span> <ul> <li>Error 1</li> <li>Error 2</li> <li>Error 3</li> </ul> </div>
but the Bootstrap warning should contain this button in the div:
<button type="button" class="close" data-dismiss="alert">×</button>
Can anyone help?
It works! - Thanks Rick B
@if (ViewData.ModelState[""] != null && ViewData.ModelState[""].Errors.Count() > 0) { <div class="alert alert-error"> <a class="close" data-dismiss="alert">×</a> <h5 class="alert-heading">Ingreso Incorrecto</h5> @Html.ValidationSummary(true) </div> }
I also had to remove the ".validation-summary-errors" class from "site.css" because this style defines a different font color and weight.
css twitter-bootstrap asp.net-mvc validationsummary
Gonzalo Dec 13 '12 at 19:48 2012-12-13 19:48
source share