I am trying to load different partial views in a single div by depending on radio button selection. when the user clicks on Individual button that partial view should appear, if click on Business then Business Partial view should appear
My view page code is
<script type="text/javascript">
$(function () {
$("[name=RegesterHere]").on('change', function () {
var $radio = $(this);
$.ajax({
url: '@Url.Action("GetRegisterForm", "Home")',
data: RegesterHere = $radio.val(),
type: 'GET',
success: function (data) {
$("#loadpartial").html(data);
}
});
});
});
</script>
<h2>GetRegisterForm</h2>
<table>
<tr>
<td colspan="1">@Html.LabelFor(m => m.RegesterHere)</td>
<td colspan="2">@Html.RadioButtonFor(m => m.RegesterHere, "Individual") Individual
@Html.RadioButtonFor(m => m.RegesterHere, "Business") Business</td>
</tr>
</table>
<div id="loadpartial">
</div>
and my controller code is
[HttpGet]
public PartialViewResult GetRegisterForm(string RegesterHere)
{
if (RegesterHere == "Individual")
{
return PartialView("IndividualPartialViewName");
}
else
{
return PartialView("BusinessPartialViewName");
}
}
Can someone help me to find the error. When I am running this code its directly showing BusinessPartialName. I am not able to see Parent View Radio Buttons in the output. Without selecting radio button it directly loading second partial view on my page.