I copied this issue from
https://github.com/aspnet/Mvc/issues/2890 because it looks like no related issues been tracked by ASP.NET MVC 5 project.
Hey, not 100% sure if this an MVC issue or Roslyn issue, but the issue exists when using DotNetCompilerPlatform 18.104.22.168 and MVC 22.214.171.124
The issue is that array variables used in an array get the wrong name (the end up being prefixed with "CS$<>8__locals1.") when used with HtmlHelper expression methods, eg Html.NameFor()
Steps to reproduce:
- In VS2015 create a new MVC5 project using the ASP.NET 4.6 template "MVC" (which already has Microsoft.CodeDom.Providers.DotNetCompilerPlatform installed)
- Replace the content /Views/Home/Index.cshtml with the razor code below
- Start the project and view the result in a browser.
Layout = null;
var someArray = new
someProperty = ""
@Html.NameFor(_ => someArray.someProperty)<br />
@for (var i = 0; i < someArray.Length; ++i)
@Html.NameFor(_ => someArray[i].someProperty)<br />
The content of the page looks like the following, when the two rows of the output should be identical.
Note that commenting out the "system.codedom" section in web.config resolves the issue by essentially disabling the DotNetCompilerPlatform package.