我正在尝试根据单选按钮选择在单个 div 中加载不同的部分视图。当用户单击“个人”按钮时,应显示部分视图,如果单击“业务”,则应显示业务部分视图
我的查看页面代码是
<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>
我的控制器代码是
[HttpGet]
public ActionResult GetRegisterForm(string RegesterHere)
{
if (RegesterHere == "Individual")
{
return PartialView("IndividualPartialViewName");
}
else
{
return PartialView("BusinessPartialViewName");
}
}
当我运行此代码时,第二个部分视图直接出现。请帮助我单击任何单选按钮,然后应加载相应的部分视图
看来您可能没有获得实际检查的单选按钮值。您可能想尝试此操作来获取选中的单选按钮值:
var value = $("input[name='RegesterHere']:checked").val();
然后在 ajax 调用中使用它:
data: RegesterHere = value,
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)