Ported from https://aspnet.codeplex.com/workitem/5888 (5 votes)
When the name contains an indexer, the Id method in Microsoft.Web.Mvc.NameExtensions generates a different Id than the one generated by the input builder.
For example if the current name is A.B[0].C, the input builder generates the id: A_B_0__C while the Id method would generate A_B[0]_C.
In the mean time, I've updated the Id method to do the following:
private static readonly Func<string, string, string> CreateSanitizedId = (Func<string, string, string>)Delegate.CreateDelegate(typeof(Func<string, string, string>), typeof(TagBuilder).GetMethod("CreateSanitizedId", BindingFlags.Static | BindingFlags.NonPublic));
public static MvcHtmlString Id(this HtmlHelper html, string name) {
return MvcHtmlString.Create(CreateSanitizedId(html.ViewData.TemplateInfo.GetFullHtmlFieldName(name), HtmlHelper.IdAttributeDotReplacement));
}
Comments: This was addressed in https://aspnetwebstack.codeplex.com/workitem/544
When the name contains an indexer, the Id method in Microsoft.Web.Mvc.NameExtensions generates a different Id than the one generated by the input builder.
For example if the current name is A.B[0].C, the input builder generates the id: A_B_0__C while the Id method would generate A_B[0]_C.
In the mean time, I've updated the Id method to do the following:
private static readonly Func<string, string, string> CreateSanitizedId = (Func<string, string, string>)Delegate.CreateDelegate(typeof(Func<string, string, string>), typeof(TagBuilder).GetMethod("CreateSanitizedId", BindingFlags.Static | BindingFlags.NonPublic));
public static MvcHtmlString Id(this HtmlHelper html, string name) {
return MvcHtmlString.Create(CreateSanitizedId(html.ViewData.TemplateInfo.GetFullHtmlFieldName(name), HtmlHelper.IdAttributeDotReplacement));
}
Comments: This was addressed in https://aspnetwebstack.codeplex.com/workitem/544