<p>Using <a href="http://www.codeplex.com/aspnet" rel="nofollow noreferrer">preview 4</a> of <a href="http://asp.net/mvc" rel="nofollow noreferrer">ASP.NET MVC</a> 
Code like:</p>

<pre><code>&lt;%= Html.CheckBox( "myCheckBox", "Click Here", "True", false ) %&gt;
</code></pre>

<p>only outputs:</p>

<pre><code>&lt;input type="checkbox"  value="True"  name="myCheckBox"  /&gt;
</code></pre>

<p>There is a <code>name</code> there for the form post back but no <code>id</code> for javascript or labels :-(</p>

<p>I was hoping that changing it to:</p>

<pre><code>Html.CheckBox( "myCheckBox", "Click Here", 
               "True", false, new { id="myCheckBox" } )
</code></pre>

<p>would work - but instead I get an exception:</p>

<pre><code>System.ArgumentException: An item with the same key has already been added.
</code></pre>

<p>As if there was already an id somewhere in a collection somewhere - I'm stumped!</p>

<p>The full exception for anyone interested follows (hey - wouldn't it be nice to attach files in here):</p>

<pre>System.ArgumentException: An item with the same key has already been added. 
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Web.Routing.RouteValueDictionary.Add(String key, Object value)
   at System.Web.Mvc.TagBuilder2.CreateInputTag(HtmlInputType inputType, String name, RouteValueDictionary attributes)
   at System.Web.Mvc.CheckBoxBuilder.CheckBox(String htmlName, RouteValueDictionary htmlAttributes)
   at System.Web.Mvc.CheckBoxBuilder.CheckBox(String htmlName, String text, String value, Boolean isChecked, RouteValueDictionary htmlAttributes)
   at System.Web.Mvc.CheckBoxExtensions.CheckBox(HtmlHelper helper, String htmlName, String text, String value, Boolean isChecked, Object htmlAttributes)
   at ASP.views_account_termsandconditions_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\dev\myProject\Views\Account\Edit.ascx:line 108</pre>

[{'answer_id': 8171, 'author': 'Nick Berardi', 'author_id': 17, 'author_profile': 'https://Stackoverflow.com/users/17', 'pm_score': 0, 'selected': False, 'text': '<p>Apparently this is a bug.  Because they are adding it to potential rendering values, they just forgot to include it.  I would recommend creating a bug on codeplex, and download the source and modify it for your needs.</p>\n'}, {'answer_id': 8289, 'author': 'Lance Fisher', 'author_id': 571, 'author_profile': 'https://Stackoverflow.com/users/571', 'pm_score': 4, 'selected': True, 'text': '<p>Try this: </p>\n\n<pre><code>&lt;%= Html.CheckBox("myCheckbox", "Click here", "True", false, new {_id ="test" })%&gt;\n</code></pre>\n\n<p>For any keyword you can use an underscore before the name of the attribute.  Instead of class you use _class.  Since class is a keyword in C#, and also the name of the attribute in HTML.  Now, "id" isn\'t a keyword in C#, but perhaps it is in another .NET language that they want to support.  From what I can tell, it\'s not a keyword in VB.NET, F#, or Ruby so maybe it is a mistake that they force you to use an underscore with it.</p>\n'}]
['https://Stackoverflow.com/questions/8147', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/193/']