javascript - use ajax to get controller action render in same page -


this code of view

i have dropdown option having value of /controllername/actionname.

when click dropdown value redirects me page selected controllername , actionname. want render view in same page using ajax. view should rendered inside empty div tag below. can me

@model demo.models.student  @{     viewbag.title = "index"; }  <h2>hello student</h2>  <select id="foo">     <option value="">pick action</option>   <option value="/home/index">home</option>     <option value="/home/profile">profile</option> </select>  <div id="main">   </div>   <script>     document.getelementbyid("foo").onchange = function () {         if (this.selectedindex !== 0) {             window.location.href = this.value;         }     }; </script> 

try this

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>‌ <script type="text/javascript">      $('#foo').change(function(){           if($(this).val()!=""&&$(this).val!=null){                $.ajax({                    url:$('#foo').val(),                    data:'',                    type:'post',                    success:function(data){                        $('#main').html(data);                    }                 })            }      }); </script> 

this load pages in main div.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -