diff --git a/global.json b/global.json index fad3dfeab0..ebe9c99ebe 100644 --- a/global.json +++ b/global.json @@ -1,3 +1,6 @@ { - "projects": ["src", "test/WebSites", "samples"] + "projects": ["src", "test/WebSites", "samples"], + "sdk": { + "version": "1.0.0-preview2-003154" + } } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionHelper.cs index 414ff0038c..8a246beb2c 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionHelper.cs @@ -101,11 +101,14 @@ public static string GetExpressionText(LambdaExpression expression, ExpressionTe // If parts start with "model", then strip that part away. if (part == null || part.NodeType != ExpressionType.Parameter) { + const string dotModel = ".model"; + var dotModelLength = dotModel.Length; + var text = builder.ToString(); - if (text.StartsWith(".model", StringComparison.OrdinalIgnoreCase)) + if (text.StartsWith(dotModel, StringComparison.OrdinalIgnoreCase) && + (text.Length == dotModelLength || text[dotModelLength] == '.' || text[dotModelLength] == '[')) { - // 6 is the length of the string ".model". - builder.Remove(0, 6); + builder.Remove(0, dotModelLength); } } diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs index 36ce863aff..aab65d2639 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs @@ -21,6 +21,9 @@ public static IEnumerable ExpressionAndTexts var Model = new TestModel(); var key = "TestModel"; var myModels = new List(); + var models = new List(); + var modelTest = new TestModel(); + var modelType = typeof(TestModel); return new TheoryData { @@ -56,6 +59,18 @@ public static IEnumerable ExpressionAndTexts (Expression>)(m => Model), string.Empty }, + { + (Expression>)(model => models[0].SelectedCategory.CategoryId), + "models[0].SelectedCategory.CategoryId" + }, + { + (Expression>)(model => modelTest.Name), + "modelTest.Name" + }, + { + (Expression>)(model => modelType), + "modelType" + }, { (Expression, Category>>)(model => model[2].SelectedCategory), "[2].SelectedCategory" @@ -157,8 +172,8 @@ public static IEnumerable EquivalentExpressions (Expression>)(m => value) }, { - // These two expressions are not actually equivalent. However ExpressionHelper returns - // string.Empty for these two expressions and hence they are considered as equivalent by the + // These two expressions are not actually equivalent. However ExpressionHelper returns + // string.Empty for these two expressions and hence they are considered as equivalent by the // cache. (Expression>)(m => Model), (Expression>)(m => m)