If the view model type is a collection, then the names generated for it (using NameFor, IdFor etc.) are incorrect (for example, it might be generated as "Project.Employees.[0].Name" - note the extra dot before "[").
The culprit is System.Web.Mvc.TemplateInfo.GetFullHtmlFieldName method. Below is the method code fixed.
public string GetFullHtmlFieldName(string partialFieldName)
{
if (string.IsNullOrWhiteSpace(partialFieldName))
return this.HtmlFieldPrefix;
// if the partial field is an array reference, the dot before it is not needed.
if (partialFieldName.StartsWith("["))
return this.HtmlFieldPrefix + partialFieldName;
else
// This uses "combine and trim" because either or both of these values might be empty
return (this.HtmlFieldPrefix + "." + partialFieldName).Trim('.');
}
Comments: Looks like it's also related to: http://aspnet.codeplex.com/workitem/7711
The culprit is System.Web.Mvc.TemplateInfo.GetFullHtmlFieldName method. Below is the method code fixed.
public string GetFullHtmlFieldName(string partialFieldName)
{
if (string.IsNullOrWhiteSpace(partialFieldName))
return this.HtmlFieldPrefix;
// if the partial field is an array reference, the dot before it is not needed.
if (partialFieldName.StartsWith("["))
return this.HtmlFieldPrefix + partialFieldName;
else
// This uses "combine and trim" because either or both of these values might be empty
return (this.HtmlFieldPrefix + "." + partialFieldName).Trim('.');
}
Comments: Looks like it's also related to: http://aspnet.codeplex.com/workitem/7711