Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.RadioButton of asp.net MVC generates id and name same

<%=Html.RadioButton("BookType", "1")  %> C# <%=Html.RadioButton("BookType", "2")  %> VB 

Above code generates Below code

<input id="BookType" name="BookType" type="radio" value="1" >C# <input id="BookType" name="BookType" type="radio" value="2" >VB 

I need same name but different ids

I want output like

*

<input id="rdoCSharp" name="BookType" type="radio" value="1" >C# <input id="rdoVb" name="BookType" type="radio" value="2" >VB 

*

like image 795
Ali Avatar asked Feb 15 '12 10:02

Ali


People also ask

What is radio button group name?

The radio button to be selected is located by two arguments: group_name is used as the name of the radio input, value is used for the value attribute or for the id attribute.

How do I add a radio button to a web form?

ASP.NET Web Forms RadioButton. It is an input control which is used to takes input from the user. It allows user to select a choice from the group of choices. To create RadioButton we can drag it from the toolbox of visual studio.


2 Answers

You can override the defaults by passing the attributes you wish to apply using an overload of the RadioButton method:

<%=Html.RadioButton("BookType", "1", new { id = "yourId" })  %> C# 
like image 118
Rich O'Kelly Avatar answered Oct 14 '22 00:10

Rich O'Kelly


<%= Html.RadioButton("BookType", "1", new { id = "rdoCSharp" }) %> C# <%= Html.RadioButton("BookType", "2", new { id = "rdoVb" }) %> VB 
like image 41
Darin Dimitrov Avatar answered Oct 13 '22 22:10

Darin Dimitrov