Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: Invalid names and ids are generated when the model type is array [544]

$
0
0
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

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>