mardi 12 janvier 2016

Validation summary for multiple partial view / forms on a view

I have 3 partial views each view HTML.BeginForm() on my main view and each have submit button. You can consider them as Login, Registration and Search views. I am using data annotation for validation of partial views and invoking the submit button using $.ajax as shown below:

if (IsFormValid()) {
    $.ajax({
            url: '/MySite/Main/LogOn',
            type: 'POST',
            data: $('#pnlLogOnConsumer').serialize(),
            success: function (result) {
                // do nothing
            },
            error: function (req, status, errorObj) {
                alert('Error');
            }
    });
} 

function IsFormValid() {
    $.validator.unobtrusive.parse($("#form1"));
    $("#form1").validate();
    return $("#form1").valid();
}

Everything works fine if I use validationsummary inside partial views. But my requirement says to have validation summary below header for each page, outside partial views. When I place validationsummary outside form tag of partial views, it doesn't work. It doesn't work even if I place the validation summary inside another form tag in another partial view.

Aucun commentaire:

Enregistrer un commentaire