我想在选择单选按钮后立即更新表单上的其他控件。
单击单选按钮后,如何让这些控件调用控制器。单独的提交(actionLink)按钮不合适。
我的代码是
<label for="ApplicationTypes_Single">On your own?</label>
@Html.RadioButtonFor(x => x.ApplicationType, "Single", new { id = "ApplicationTypes_Single" })
<label for="ApplicationTypes_Joint">With someone else?</label>
@Html.RadioButtonFor(x => x.ApplicationType, "Joint", new { id="ApplicationTypes_Joint" })
依赖于该选择的控件是
@if(Model.ApplicationType == AffordabilityPage1.ApplicationTypes.Joint)
{
@Html.LabelFor(model => model.SecondAge)
@Html.EditorFor(model => model.SecondAge)
}
非常感谢您给出的任何提示。
答案 0 :(得分:1)
你需要javascript才能实现这一目标。例如,如果您使用的是jquery,则可以订阅这些单选按钮的更改事件并采取一些操作:
$(function() {
$(':radio[id^="ApplicationTypes"]').change(function() {
var value = $(this).val(); // will equal Single or Joint
// Depending on what you are trying to achieve either send an AJAX request
// or force the submission of some form in order to send the new value to the server
});
});