【发布时间】:2010-09-05 16:59:18
【问题描述】:
使用preview 4 的ASP.NET MVC 代码如下:
<%= Html.CheckBox( "myCheckBox", "Click Here", "True", false ) %>
仅输出:
<input type="checkbox" value="True" name="myCheckBox" />
有一个name 用于回发表单,但没有id 用于javascript 或标签:-(
我希望将其更改为:
Html.CheckBox( "myCheckBox", "Click Here",
"True", false, new { id="myCheckBox" } )
会起作用 - 但我得到了一个例外:
System.ArgumentException: An item with the same key has already been added.
好像某个集合中的某个地方已经有一个 id - 我很难过!
任何感兴趣的人的完整例外如下(嘿-在这里附加文件不是很好吗):
System.ArgumentException:已添加具有相同键的项目。 在 System.ThrowHelper.ThrowArgumentException(ExceptionResource 资源) 在 System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) 在 System.Web.Routing.RouteValueDictionary.Add(字符串键,对象值) 在 System.Web.Mvc.TagBuilder2.CreateInputTag(HtmlInputType inputType,字符串名称,RouteValueDictionary 属性) 在 System.Web.Mvc.CheckBoxBuilder.CheckBox(字符串 htmlName,RouteValueDictionary htmlAttributes) 在 System.Web.Mvc.CheckBoxBuilder.CheckBox(字符串 htmlName,字符串文本,字符串值,布尔 isChecked,RouteValueDictionary htmlAttributes) 在 System.Web.Mvc.CheckBoxExtensions.CheckBox(HtmlHelper 助手,字符串 htmlName,字符串文本,字符串值,布尔 isChecked,对象 htmlAttributes) 在 ASP.views_account_termsandconditions_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) 在 c:\dev\myProject\Views\Account\Edit.ascx:line 108
【问题讨论】: