我想在选择单选按钮后立即更新表单上的其他控件。
如何让这些控件在单击单选按钮后立即调用控制器。单独的提交(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)
}
非常感谢您提供的任何提示。
您需要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
});
});