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: Resolved: 34bba04004c5d1af73137ba34aa97c51e8f50635
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: Resolved: 34bba04004c5d1af73137ba34aa97c51e8f50635