代码之家  ›  专栏  ›  技术社区  ›  dilipkumar1007

mvc中的绑定单选按钮

  •  0
  • dilipkumar1007  · 技术社区  · 11 年前
    Radio Button checked item should be true based on entry.isalbum value. Below is my View code..    
    
    @foreach(abc.Models.ddt entry in entrydetails)
            {    
        @if(entry.isAlbum=="Album")
            {
            <input type="radio" id="c" name="isAlbum" checked="checked" value="Album" />
    
             <label style="margin-right:10px" for="c"><span></span>Album</label>
                }
    
             <input type="radio" id="c1" name="isAlbum"  value="Movies" />
    
             <label style="margin-right:10px" for="c1"><span></span>Movies</label>
    
             <input type="radio" id="c2"  name="isAlbum" value="Single" />
    
             <label style="margin-right:10px" for="c2"><span></span>Single</label>
    
            </div>
        }
        }
    

    foreach循环包含数据库中与专辑、电影或单曲对应的stroed值。 根据entry.isAlbum值,选中的单选按钮应为true。我们怎样才能做到这一点,请帮助我们?我在上面的代码中有三个单选按钮。根据输入,选中的单选按钮将为真。Isalbum vale。请帮帮我

    1 回复  |  直到 11 年前
        1
  •  1
  •   Jeyhun Rahimov    11 年前

    试试看:

    <input type="radio" id="c" name="isAlbum" @if(entry.isAlbum=="Album"){<text>checked="checked"</text>} value="Album" />
    
    <input type="radio" id="c1" name="isAlbum" @if(entry.isAlbum=="Movies"){<text>checked="checked"</text>} value="Movies" />
    
    <input type="radio" id="c2" name="isAlbum" @if(entry.isAlbum=="Single"){<text>checked="checked"</text>} value="Single" />