Usando preview 4 de ASP.NET MVC código como:¿Cómo se obtiene un ID personalizado para hacer uso de HtmlHelper en MVC
<%= Html.CheckBox("myCheckBox", "Click Here", "True", false) %>
única salidas:
<input type="checkbox" value="True" name="myCheckBox" />
Hay una name
allí para el formulario de envío pero no id
para javascript o etiquetas :-(
Tenía la esperanza de cambiarlo a:
Html.CheckBox("myCheckBox", "Click Here",
"True", false, new { id="myCheckBox" })
funcionaría - pero en cambio obtener una excepción:
System.ArgumentException: An item with the same key has already been added.
Como si ya era un id en algún lugar de una colección en algún lugar - Estoy perplejo!
La excepción completa para cualquier persona interesada sigue (hey - no sería agradable para adjuntar archivos de aquí):
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
¿dónde está esto descrito en la documentación? –
No sé si en la documentación. No pude encontrarlo Creo que acabo de leerlo en el blog de Phil Haacks. Además, creo que el prefijo se cambió a un @ de un guión bajo, por lo que debes probar "nuevo {@ id =" test "} si lo anterior no funciona. –