HendPro12
HendPro12

Reputation: 1104

Partial View Refresh and Script Doesnt Work

In my C# MVC4 application, I have a partial view that contains these two scripts:

<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
        $('.rowselection').click(function (e) {
            var tdata = $('#form1').serialize();
            $.ajax({
                type: "POST",
                data: tdata,
                url: "/Home/PartialAverage",
                success: function (result) { success(result); }
            });
        });

        function success(result) {
            $("#Display_Average").html(result);
        }
    });
</script>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
        if ($('.AVEexists').length) {
            $('#SubmitButton').hide();
        }
    });
</script>

When the partial view is refreshed the first script still works as desired. The second script however, does not appear to work because the button which is hidden correctly the first time the partial is loaded does not reappear when the partial is refreshed and not containing any elements with the class .AVEexists

What could be causing this?

Upvotes: 0

Views: 125

Answers (1)

Stefan
Stefan

Reputation: 651

Is this your whole partial view? Or are those .AVEexists elements inside this partial view? And if the submit button is outside your partial view, shouldn't you be doing

$(document).ready(function () {
    if ($('.AVEexists').length) {
        $('#SubmitButton').hide();
    }
    else {
        $('#SubmitButton').show();
    }

});

in the second script?

Upvotes: 2

Related Questions