ajax - How to load Different Partial Views on the same div by radio button selection? -


enter code here *mainview.cshtml*: @radiobuttonfor(m=>m.registeras,individual) @radiobuttonfor(m=>m.registeras,businessentity) <div id="loadpartial"> </div> 

i have register form in user can register individual or business entity. kept 2 radio buttons. if user selects individual radio button, partial view should loaded. if user selects business entity radio button second partial view should loaded on same div. new asp.net mvc4 razor. can please give sample code.

you have use jquery in order make ajax calls.

first reference jquery @ bottom of page.

in controller, define , implement method returns partial view.

[httpget] public actionresult getregisterform(int registeras) {     if(registeras == individual)     {         return partialview("individualpartialviewname");     }     else     {         return partialview("businesspartialviewname");     } } 

now in view, can call above action using ajax.

<script type="text/javascript">     $(function(){         $("[name=registeras]").on('change', function(){             var $radio = $(this);             $.ajax({                 url:'@url.action("getregisterform", "controllername")',                 data: { registeras = $radio.val() }                 type: 'get',                 success: function(data){                     $("#loadpartial").html(data);                 }         });     }); </script> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -