@ Html.RadioButton用于回发

问题描述

| 选择单选按钮后,我想更新表单上的其他控件。 单击单选按钮后,如何使这些控件立即调用控制器。单独的提交(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,则可以订阅这些单选按钮的change事件并采取一些措施:
$(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
    });
});