Refresh only partial view in MVC4

放肆的年华 提交于 2019-12-10 03:34:34

问题


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?


回答1:


try to use this delegate to handle click event

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

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

            });


来源:https://stackoverflow.com/questions/17776929/refresh-only-partial-view-in-mvc4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!