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 "[").<br /><br />The culprit is System.Web.Mvc.TemplateInfo.GetFullHtmlFieldName method. Below is the method code fixed.<br /><br />public string GetFullHtmlFieldName(string partialFieldName)<br />{<br /> if (string.IsNullOrWhiteSpace(partialFieldName))<br /> return this.HtmlFieldPrefix;<br /><br /> // if the partial field is an array reference, the dot before it is not needed.<br /> if (partialFieldName.StartsWith("["))<br /> return this.HtmlFieldPrefix + partialFieldName;<br /> else<br /> // This uses "combine and trim" because either or both of these values might be empty<br /> return (this.HtmlFieldPrefix + "." + partialFieldName).Trim('.');<br />}
↧