Friday, June 17, 2016

Did you know that if you wrap a radio button and some adjacent copy in a label tag that if you click up to copy it will affect the radio button as though you clicked it too?

<div>
   <label>
      <input type="radio" name="Connection" value="Heart">
      Heart
   </label>
</div>
<div>
   <label>
      <input type="radio" name="Connection" value="Spade">
      Spade
   </label>
</div>

 
 

While I'm on this ASP.NET MVC will model bind based on the name of a radio button and not the id as, duh, obviously the id should not be the same across numerous radio buttons, and, yet, .NET has a bad habit of just assigning the same id to numerous radio buttons. If you want to fight this "feature" in the RadioButtonFor Razor markup you may do so like this:

@Html.RadioButtonFor(m => m.Connection, "Heart", new {id="heart"})

No comments:

Post a Comment