Form does not validate using Partial View

0

I'm using Partial View to Pessoa record, that is, in my View have two RadioButton : Pessoa Fisica and Pessoa Juridica , to select the Radio Button I do the following ajax :

    $(function () {
    $(".radioPessoa").change(function (event) {
        var opcao = $(this).val();
        $.ajax({
            url: '@Url.Action("OpcaoPessoa", "Cadastro")',
            data: { opcao: opcao },
            type: 'GET',
            success: function (data) {
                $(".loadpartial").html(data);
            }
        });
    });
});

There, I have these two files .cshtml which contains the required inputs, Everything is working so far, AND when I give submit, it does not validate my inputs, I put the requirements in my Model %

In my View Create I left the class to receive inputs and submit :

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)

<div class="loadpartial">
</div>

<div class="col-xs-12 col-md-12 semPadding marginCimaBaixo clearfix">
    <input type="submit" value="Salvar" class="btn btn-success" />
</div>

}

Then my content from files .cshtml will load into div , segue meu Model: '

    [Required(ErrorMessage = "Campo CPF deve ser preenchido")]
    [RegularExpression(@"[0-9.-]{14}", ErrorMessage = "Por favor, preencha o CPF apenas com números.")]
    public string CPF { get; set; }

In short, it does not validate my inputs and goes to Controller

    
asked by anonymous 26.11.2015 / 11:34

1 answer

0

I put this code, after I received the AJAX

 //allow the validation framework to re-prase the DOM
 jQuery.validator.unobtrusive.parse(); 

 //or to give the parser some context, supply it with a selector
 //jQuery validator will parse all child elements (deep) starting
 //from the selector element supplied
 jQuery.validator.unobtrusive.parse("#formId");
    
26.11.2015 / 12:38