简体   繁体   English

在MVC4中仅刷新部分视图

[英]Refresh only partial view in MVC4

I'm having a little bit of trouble with refreshing a partialview on mvc4, here is the code: 我在刷新mvc4的部分视图时遇到了一些麻烦,这里是代码:

    <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? 当我第一次按下其中一个按钮时,它会在DIV内部呈现部分视图,但是当我再次按下它时,没有任何反应,原因是什么?

try to use this delegate to handle click event 尝试使用此委托来处理click事件

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

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

            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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