简体   繁体   中英

Refresh only partial view in MVC4

I'm having a little bit of trouble with refreshing a partialview on mvc4, here is the code:

    <div id="partialViewDiv"></div>

    <input type="button" id="firstPartialLink" value="Change Div"/>
    <input type="button" id="secondPartialLink" value="Change Div"/>

    <script type="text/javascript">
        $(function() {
            $("#firstPartialLink").click(function() {

                $("#partialViewDiv").load('@Url.Action("GetDiv", "Home")');

            });

            $("#secondPartialLink").click(function () {

                $("#partialViewDiv").load('@Url.Action("GetDiv2", "Home")');
            });
        })

    </script>

When I press one of the buttons the first time, it renders the partialview inside the DIV, but when I press it again, nothing happens, what would be the cause?

try to use this delegate to handle click event

            $(document).on("click","#firstPartialLink",function() {

                $("#partialViewDiv").load('/Home/GetDiv',function(html) { if need it});

            });

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