简体   繁体   中英

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM