在MVC4中仅刷新部分视图 [英] Refresh only partial view in MVC4
本文介绍了在MVC4中仅刷新部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
刷新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>
当我第一次按下其中一个按钮时,它会在DIV中渲染局部视图,但是当我再次按下它时,什么也没发生,那是什么原因?
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});
});
这篇关于在MVC4中仅刷新部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文