Show ValidationSummary MVC3 as “alert-error” Bootstrap

后端 未结 16 1256
情书的邮戳
情书的邮戳 2021-01-30 00:51

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         


        
16条回答
  •  渐次进展
    2021-01-30 01:31

    Expanding upon Daniel Björk's solution you can include a little script to adjust the CSS included with ValidationSummary() output. The resulting bootstrap alert was showing a rendering issue until I removed the validation-summary-errors class.

    @if (ViewData.ModelState.Any(x => x.Value.Errors.Any())) {
       
    ×

    Validation Errors

    @Html.ValidationSummary()
    }

    You can also easily give a bootstrap highlight to fields with errors. See http://chadkuehn.com/convert-razor-validation-summary-into-bootstrap-alert/

提交回复
热议问题