Apply Twitter Bootstrap Validation Style and Message to ASP.NET MVC validation

前端 未结 12 1635
星月不相逢
星月不相逢 2021-01-30 00:57

How can I integrate ASP.NET MVC unobtrusive validation and Twitter Bootstrap? I want to have all those validation messages and styles appropria

12条回答
  •  旧巷少年郎
    2021-01-30 01:49

    This will convert ValidationSummary() to a boostrap alert. You can include a little script to remove unnecessary classes and give a highlight to fields with problems.

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

    Validation Errors

    @Html.ValidationSummary()
    }

    See more information at http://chadkuehn.com/convert-razor-validation-summary-into-bootstrap-alert/

提交回复
热议问题