c# – VallidationSummary does not show any errors on the screen

Question:

I'm using ValidationSummary on forms, but they aren't being rendered. Is there any known reason for this error?

Example of form:

@using (Html.BeginForm("CadastrarPessoaFisica", "Usuario", FormMethod.Post))
{
    @Html.ValidationSummary(false)
    <div class="col-md-6 column">
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
            @Html.TextBoxFor(e => e.Nome, new { @class = "form-control input-sm", placeholder = "Nome" })
        </div><br />

        <div class="input-group">
            <span class="input-group-addon">
                <i class="glyphicon glyphicon-envelope"></i>
            </span>
            @Html.TextBoxFor(e => e.Email, new { @class = "form-control input-sm", placeholder = "Email", type = "email" })
        </div><br />

        <div class="input-group">
            <span class="input-group-addon">
                <i class="glyphicon glyphicon-phone">
                </i>
            </span>
            @Html.TextBoxFor(e => e.Telefone, new { @class = "form-control input-sm", placeholder = "Telefone" })
        </div><br />

        <div class="input-group">
            <span class="input-group-addon">
                <i class="glyphicon glyphicon-phone">
                </i>
            </span>
            @Html.TextBoxFor(e => e.Celular, new { @class = "form-control input-sm", placeholder = "Celular" })
        </div><br />


        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
            @Html.TextBoxFor(e => e.CPF, new { @class = "form-control input-sm", placeholder = "CPF" })
        </div>

        <br />
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
            @Html.TextBoxFor(e => e.Password, new { @class = "form-control input-sm", placeholder = "Senha" })
        </div>
        <br />
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
            @Html.TextBoxFor(e => e.Endereco.CEP, new { @class = "form-control input-sm", placeholder = "Cep" })
        </div>
    </div>
    <div class="col-md-6 column">
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
            @Html.TextBoxFor(e => e.Endereco.Rua, new { @class = "form-control input-sm", placeholder = "Rua" })
        </div>

        <br />
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
            @Html.TextBoxFor(e => e.Endereco.Numero, new { @class = "form-control input-sm", placeholder = "Numero" })
        </div>

        <br />
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
            @Html.TextBoxFor(e => e.Endereco.Complemento, new { @class = "form-control input-sm", placeholder = "Complemento" })
        </div>
        <br />
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
            @Html.TextBoxFor(e => e.Endereco.Bairro, new { @class = "form-control input-sm", placeholder = "Bairro" })
        </div>


        <br />
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
            @Html.TextBoxFor(e => e.Endereco.Cidade, new { @class = "form-control input-sm", placeholder = "Cidade" })
        </div>
        <br />
        <div class="input-group">
            <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span>
            @Html.DropDownListFor(e => e.Endereco.Estado, ViewBag.Estado as IEnumerable<SelectListItem>, new { @class = "form-control" })
        </div>
        <br />
    </div>

    <div style="text-align:center;">
        <input type="checkbox" /> Eu concordo com os termos
    </div><br />

    <div class="col-md-12 responsive">
        <input type="submit" value="Registrar" class="btn btn-success btn-block">
    </div>
}

Answer:

Possibly the jQuery Unobstrusive Validation is missing. The best thing is to use the following NuGet package in your solution:

https://www.nuget.org/packages/jQuery.Validation.Unobtrusive/

Add the JS scripts to the layout that should work.

Scroll to Top