C# 使用jquery选中单选按钮时,如何显示文本框和下拉列表?

C# 使用jquery选中单选按钮时,如何显示文本框和下拉列表?,c#,jquery,asp.net-mvc,C#,Jquery,Asp.net Mvc,大家好,我有一些单选按钮和对应于每个单选按钮的文本框。我想做的是当选中单选按钮时,按以下格式显示相应的文本框 @foreach(var item in Viewbag.Ids) { <div class="group"> <label class="label"> @Html.RadioButton("Rdbtn",new{value=@item.value})

大家好,我有一些单选按钮和对应于每个单选按钮的文本框。我想做的是当选中单选按钮时,按以下格式显示相应的文本框

        @foreach(var item in Viewbag.Ids)
        {
         <div class="group">
          <label class="label">
           @Html.RadioButton("Rdbtn",new{value=@item.value})
          </label>
            <div class="control">
                  <input type="text"  />
            <div>
        </div>

这工作正常,我想在选中“@Html.RadioButtonFor(m=>m.IsTax)”时显示dropdwon。我如何才能做到这一点,我必须在编辑模式下选中单选按钮,如果选中,有人能帮我做这件事吗

更改razor代码以添加类

 @Html.RadioButton("Rdbtn",new{ .value = @item.value , .class = "radio1"})
然后将jquery更改为:

$('.radio1').change( function(){
  if($(this).is(':checked')){
       $(this).closest('input').show();
  }
第二个问题

在每一个收音机中添加一个类

  @Html.RadioButton("Rdbtn",new{value=@item.value, new { .class = "radio2"})
然后jquery

$('.radio2').change(function(e){
  e.preventDefault(); //im not too sure you need this
  $('.radio2').attr('checked', false);
  $(this).attr('checked', true);    
});

正如我在评论中所说,对于第二个问题的回答,我强烈建议你不要这样做,甚至不确定它是否真的会起作用。该脚本将在客户端工作,它将执行您想要的操作,但在服务器端,它可能会抛出错误,试图以这种方式将单选按钮绑定到bools。同样,这个答案是因为你自找的——这不是正确的方法。

我可以很快为你写这封信,但是。。。“m.IsFlat”,“m.IsFree”-这些听起来像布尔的,你确定你已经想到了这个,你不想要布尔的复选框吗?然后,如果选中一个复选框,则编写脚本?单选按钮都应该绑定到一个值。@ScottSelby这些是布尔值,这些是单选按钮,这是这里的要求…你能向sol提供两种方式吗?这对我很有帮助。。
  @Html.RadioButton("Rdbtn",new{value=@item.value, new { .class = "radio2"})
$('.radio2').change(function(e){
  e.preventDefault(); //im not too sure you need this
  $('.radio2').attr('checked', false);
  $(this).attr('checked', true);    
});