Merging ModelBinding into Mvc.Core
This commit is contained in:
parent
572e57e25c
commit
9fded74b15
|
|
@ -15,12 +15,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Razor"
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Core", "src\Microsoft.AspNet.Mvc.Core\Microsoft.AspNet.Mvc.Core.xproj", "{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.ModelBinding", "src\Microsoft.AspNet.Mvc.ModelBinding\Microsoft.AspNet.Mvc.ModelBinding.xproj", "{FA915D3D-22C3-4478-97F2-A81D28B6C503}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Common", "src\Microsoft.AspNet.Mvc.Common\Microsoft.AspNet.Mvc.Common.xproj", "{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.ModelBinding.Test", "test\Microsoft.AspNet.Mvc.ModelBinding.Test\Microsoft.AspNet.Mvc.ModelBinding.Test.xproj", "{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Razor.Test", "test\Microsoft.AspNet.Mvc.Razor.Test\Microsoft.AspNet.Mvc.Razor.Test.xproj", "{3F6E355E-4869-41D9-943B-D54771221A7F}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Core.Test", "test\Microsoft.AspNet.Mvc.Core.Test\Microsoft.AspNet.Mvc.Core.Test.xproj", "{A8AA326E-8EE8-4F11-B750-23028E0949D7}"
|
||||
|
|
@ -110,16 +106,6 @@ Global
|
|||
{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -130,16 +116,6 @@ Global
|
|||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{3F6E355E-4869-41D9-943B-D54771221A7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3F6E355E-4869-41D9-943B-D54771221A7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3F6E355E-4869-41D9-943B-D54771221A7F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -395,9 +371,7 @@ Global
|
|||
{079EFA1F-0B0A-4853-B27B-5780D111CD85} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{314E9AD6-2FFC-4A92-A8AD-510658C64F1E} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{3F6E355E-4869-41D9-943B-D54771221A7F} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{A8AA326E-8EE8-4F11-B750-23028E0949D7} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{FBB2B86E-972B-4185-9FF2-62CAB5F8388F} = {DAAE4C74-D06F-4874-A166-33305D2643CE}
|
||||
|
|
|
|||
26
Mvc.sln
26
Mvc.sln
|
|
@ -15,12 +15,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Razor"
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Core", "src\Microsoft.AspNet.Mvc.Core\Microsoft.AspNet.Mvc.Core.xproj", "{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.ModelBinding", "src\Microsoft.AspNet.Mvc.ModelBinding\Microsoft.AspNet.Mvc.ModelBinding.xproj", "{FA915D3D-22C3-4478-97F2-A81D28B6C503}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Common", "src\Microsoft.AspNet.Mvc.Common\Microsoft.AspNet.Mvc.Common.xproj", "{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.ModelBinding.Test", "test\Microsoft.AspNet.Mvc.ModelBinding.Test\Microsoft.AspNet.Mvc.ModelBinding.Test.xproj", "{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Razor.Test", "test\Microsoft.AspNet.Mvc.Razor.Test\Microsoft.AspNet.Mvc.Razor.Test.xproj", "{3F6E355E-4869-41D9-943B-D54771221A7F}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Core.Test", "test\Microsoft.AspNet.Mvc.Core.Test\Microsoft.AspNet.Mvc.Core.Test.xproj", "{A8AA326E-8EE8-4F11-B750-23028E0949D7}"
|
||||
|
|
@ -208,16 +204,6 @@ Global
|
|||
{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -228,16 +214,6 @@ Global
|
|||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{3F6E355E-4869-41D9-943B-D54771221A7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3F6E355E-4869-41D9-943B-D54771221A7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3F6E355E-4869-41D9-943B-D54771221A7F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -1014,9 +990,7 @@ Global
|
|||
{079EFA1F-0B0A-4853-B27B-5780D111CD85} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{314E9AD6-2FFC-4A92-A8AD-510658C64F1E} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{C48DA9D7-ACB5-4408-AA79-27ECB60A67EF} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{FA915D3D-22C3-4478-97F2-A81D28B6C503} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{F3DF6D0B-16FE-4402-B92C-7243A75CF1FD} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
|
||||
{3B8DC0C0-6C55-4034-AD96-DE1000928E6B} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{3F6E355E-4869-41D9-943B-D54771221A7F} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{A8AA326E-8EE8-4F11-B750-23028E0949D7} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
|
||||
{FBB2B86E-972B-4185-9FF2-62CAB5F8388F} = {DAAE4C74-D06F-4874-A166-33305D2643CE}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -32,7 +32,6 @@ namespace Microsoft.AspNet.Mvc
|
|||
"Microsoft.AspNet.Mvc",
|
||||
"Microsoft.AspNet.Mvc.Abstractions",
|
||||
"Microsoft.AspNet.Mvc.Core",
|
||||
"Microsoft.AspNet.Mvc.ModelBinding",
|
||||
"Microsoft.AspNet.Mvc.Razor",
|
||||
"Microsoft.AspNet.Mvc.Razor.Host",
|
||||
"Microsoft.AspNet.Mvc.TagHelpers",
|
||||
|
|
|
|||
|
|
@ -675,7 +675,7 @@ namespace Microsoft.AspNet.Mvc.Description
|
|||
}
|
||||
else
|
||||
{
|
||||
return ModelBindingHelper.CreatePropertyModelName(containerName, metadata.PropertyName);
|
||||
return ModelNames.CreatePropertyModelName(containerName, metadata.PropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -8,7 +8,6 @@ using System.Diagnostics;
|
|||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding.Internal;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -105,9 +104,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
// Used when the ValueProvider contains the collection to be bound as multiple elements, e.g. foo[0], foo[1].
|
||||
private async Task<IEnumerable<TElement>> BindComplexCollection(ModelBindingContext bindingContext)
|
||||
{
|
||||
var indexPropertyName = ModelBindingHelper.CreatePropertyModelName(bindingContext.ModelName, "index");
|
||||
var indexPropertyName = ModelNames.CreatePropertyModelName(bindingContext.ModelName, "index");
|
||||
var valueProviderResultIndex = await bindingContext.ValueProvider.GetValueAsync(indexPropertyName);
|
||||
var indexNames = CollectionModelBinderUtil.GetIndexNamesFromValueProviderResult(valueProviderResultIndex);
|
||||
var indexNames = GetIndexNamesFromValueProviderResult(valueProviderResultIndex);
|
||||
|
||||
return await BindComplexCollectionFromIndexes(bindingContext, indexNames);
|
||||
}
|
||||
|
|
@ -134,7 +133,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
var boundCollection = new List<TElement>();
|
||||
foreach (var indexName in indexNames)
|
||||
{
|
||||
var fullChildName = ModelBindingHelper.CreateIndexModelName(bindingContext.ModelName, indexName);
|
||||
var fullChildName = ModelNames.CreateIndexModelName(bindingContext.ModelName, indexName);
|
||||
var childBindingContext = ModelBindingContext.GetChildModelBindingContext(
|
||||
bindingContext,
|
||||
fullChildName,
|
||||
|
|
@ -234,5 +233,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
// fallback
|
||||
return new[] { rawValue };
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetIndexNamesFromValueProviderResult(ValueProviderResult valueProviderResult)
|
||||
{
|
||||
IEnumerable<string> indexNames = null;
|
||||
if (valueProviderResult != null)
|
||||
{
|
||||
var indexes = (string[])valueProviderResult.ConvertTo(typeof(string[]));
|
||||
if (indexes != null && indexes.Length > 0)
|
||||
{
|
||||
indexNames = indexes;
|
||||
}
|
||||
}
|
||||
|
||||
return indexNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
var dto = (ComplexModelDto)bindingContext.Model;
|
||||
foreach (var propertyMetadata in dto.PropertyMetadata)
|
||||
{
|
||||
var propertyModelName = ModelBindingHelper.CreatePropertyModelName(
|
||||
var propertyModelName = ModelNames.CreatePropertyModelName(
|
||||
bindingContext.ModelName,
|
||||
propertyMetadata.BinderModelName ?? propertyMetadata.PropertyName);
|
||||
|
||||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding.Internal;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
var propertyModelMetadata =
|
||||
parentBindingContext.OperationBindingContext.MetadataProvider.GetMetadataForType(typeof(TModel));
|
||||
var propertyModelName =
|
||||
ModelBindingHelper.CreatePropertyModelName(parentBindingContext.ModelName, propertyName);
|
||||
ModelNames.CreatePropertyModelName(parentBindingContext.ModelName, propertyName);
|
||||
var propertyBindingContext = ModelBindingContext.GetChildModelBindingContext(
|
||||
parentBindingContext,
|
||||
propertyModelName,
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Globalization;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding
|
||||
{
|
||||
public static class ModelNames
|
||||
{
|
||||
public static string CreateIndexModelName(string parentName, int index)
|
||||
{
|
||||
return CreateIndexModelName(parentName, index.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public static string CreateIndexModelName(string parentName, string index)
|
||||
{
|
||||
return (parentName.Length == 0) ? "[" + index + "]" : parentName + "[" + index + "]";
|
||||
}
|
||||
|
||||
public static string CreatePropertyModelName(string prefix, string propertyName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(prefix))
|
||||
{
|
||||
return propertyName ?? string.Empty;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(propertyName))
|
||||
{
|
||||
return prefix ?? string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return prefix + "." + propertyName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ using System.ComponentModel;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding.Internal;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
isAnyPropertyEnabledForValueProviderBasedBinding = true;
|
||||
|
||||
var propertyModelName = ModelBindingHelper.CreatePropertyModelName(
|
||||
var propertyModelName = ModelNames.CreatePropertyModelName(
|
||||
context.ModelBindingContext.ModelName,
|
||||
propertyMetadata.BinderModelName ?? propertyMetadata.PropertyName);
|
||||
|
||||
|
|
@ -395,7 +395,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
var propertyExplorer = modelExplorer.GetExplorerForProperty(missingRequiredProperty, model: null);
|
||||
|
||||
var propertyName = propertyExplorer.Metadata.BinderModelName ?? missingRequiredProperty;
|
||||
var modelStateKey = ModelBindingHelper.CreatePropertyModelName(
|
||||
var modelStateKey = ModelNames.CreatePropertyModelName(
|
||||
bindingContext.ModelName,
|
||||
propertyName);
|
||||
|
||||
|
|
@ -412,7 +412,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
{
|
||||
bindingContext.ModelState.TryAddModelError(
|
||||
modelStateKey,
|
||||
Resources.FormatMissingRequiredMember(propertyName));
|
||||
Resources.FormatModelBinding_MissingRequiredMember(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -529,7 +529,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
|
|||
var validationState = bindingContext.ModelState.GetFieldValidationState(modelStateKey);
|
||||
if (validationState == ModelValidationState.Unvalidated)
|
||||
{
|
||||
var errorMessage = Resources.ModelBinderConfig_ValueRequired;
|
||||
var errorMessage = Resources.ModelBinding_ValueRequired;
|
||||
bindingContext.ModelState.TryAddModelError(modelStateKey, errorMessage);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding.Internal
|
||||
|
|
@ -20,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal
|
|||
internal PrefixContainer([NotNull] ICollection<string> values)
|
||||
{
|
||||
_originalValues = values;
|
||||
_sortedValues = _originalValues.ToArrayWithoutNulls();
|
||||
_sortedValues = ToArrayWithoutNulls(_originalValues);
|
||||
Array.Sort(_sortedValues, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
|
|
@ -187,6 +188,36 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Internal
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert an ICollection to an array, removing null values. Fast path for case where
|
||||
/// there are no null values.
|
||||
/// </summary>
|
||||
private static T[] ToArrayWithoutNulls<T>(ICollection<T> collection) where T : class
|
||||
{
|
||||
Debug.Assert(collection != null);
|
||||
|
||||
var result = new T[collection.Count];
|
||||
var count = 0;
|
||||
foreach (T value in collection)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
result[count] = value;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == collection.Count)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
var trimmedResult = new T[count];
|
||||
Array.Copy(result, trimmedResult, count);
|
||||
return trimmedResult;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class PrefixComparer : IComparer<String>
|
||||
{
|
||||
private readonly string _prefix;
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNet.Mvc.Core;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
||||
|
|
@ -156,7 +156,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
|
||||
foreach (var childMetadata in metadata.Properties)
|
||||
{
|
||||
var childKey = ModelBindingHelper.CreatePropertyModelName(currentModelKey, childMetadata.PropertyName);
|
||||
var childKey = ModelNames.CreatePropertyModelName(currentModelKey, childMetadata.PropertyName);
|
||||
var validationState = modelState.GetFieldValidationState(childKey);
|
||||
|
||||
if (validationState == ModelValidationState.Unvalidated)
|
||||
|
|
@ -186,7 +186,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
};
|
||||
|
||||
var propertyBindingName = propertyMetadata.BinderModelName ?? propertyMetadata.PropertyName;
|
||||
var childKey = ModelBindingHelper.CreatePropertyModelName(currentModelKey, propertyBindingName);
|
||||
var childKey = ModelNames.CreatePropertyModelName(currentModelKey, propertyBindingName);
|
||||
|
||||
if (!ValidateNonVisitedNodeAndChildren(
|
||||
childKey,
|
||||
|
|
@ -224,7 +224,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
if (element != null || anyValidatorsDefined)
|
||||
{
|
||||
var elementExplorer = new ModelExplorer(_modelMetadataProvider, elementMetadata, element);
|
||||
var elementKey = ModelBindingHelper.CreateIndexModelName(currentKey, index);
|
||||
var elementKey = ModelNames.CreateIndexModelName(currentKey, index);
|
||||
var elementValidationContext = new ValidationContext()
|
||||
{
|
||||
ModelValidationContext = ModelValidationContext.GetChildValidationContext(
|
||||
|
|
@ -283,7 +283,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
|
|||
{
|
||||
foreach (var error in validator.Validate(modelValidationContext))
|
||||
{
|
||||
var errorKey = ModelBindingHelper.CreatePropertyModelName(modelKey, error.MemberName);
|
||||
var errorKey = ModelNames.CreatePropertyModelName(modelKey, error.MemberName);
|
||||
if (!modelState.TryAddModelError(errorKey, error.Message) &&
|
||||
modelState.GetFieldValidationState(errorKey) == ModelValidationState.Unvalidated)
|
||||
{
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue