dilipkumar1007
dilipkumar1007

Reputation: 363

bind radiobutton in mvc

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 loop contain value stroed in database corresponding to Album, Movies or Single. radio button checked should be true based on entry.isAlbum vale. How can we do this, please help to us? I have three radiobutton mention in above code. Radio Button checked will be true based on entry.Isalbum vale. Please help me

Upvotes: 0

Views: 69

Answers (1)

Jeyhun Rahimov
Jeyhun Rahimov

Reputation: 3787

Try this:

<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" />

Upvotes: 1

Related Questions