Refresh only partial view in MVC4

I have some problems updating partial view 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 click one of the buttons for the first time, it displays a partial view inside the DIV, but when I click it again, nothing happens, what will be the reason?

+8
jquery c # asp.net-mvc asp.net-mvc-partialview
source share
1 answer

try using this delegate to handle the click event

  $(document).on("click","#firstPartialLink",function() { $("#partialViewDiv").load('/Home/GetDiv',function(html) { if need it}); }); 
+11
source share

All Articles