Show ValidationSummary MVC3 as “alert-error” Bootstrap

后端 未结 16 989
情书的邮戳
情书的邮戳 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:37

    I took a slightly different route: using JQuery to hook into the form submit:

    $('form').each(function() {
        var theForm = $(this);
        theForm.submit(function() {
            if ($(this).valid()) {
                if ($(this).find('.validation-summary-valid').length) {
                    $('.validation-summary-errors').hide();
                }
            } else {
                if ($(this).find('.validation-summary-errors').length) {
                    $('.validation-summary-errors')
                        .addClass('alert alert-error')
                        .prepend('

    Validation Exceptions:

    '); } } }); });

    I have this set inside a self-executing javascript module so that it hooks onto any validation summaries that I create.

    HTH

    Chuck

提交回复
热议问题