diff --git a/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageActivator.cs b/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageActivator.cs index 4000df8184..fb9483856d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageActivator.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor/RazorPageActivator.cs @@ -4,8 +4,8 @@ using System; using System.Collections.Concurrent; using System.Diagnostics; -using System.Reflection; using System.Linq.Expressions; +using System.Reflection; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Razor.Internal; using Microsoft.AspNetCore.Mvc.Rendering; @@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor private ViewDataDictionary CreateViewDataDictionary(ViewContext context, PageActivationInfo activationInfo) { // Create a ViewDataDictionary if the ViewContext.ViewData is not set or the type of - // ViewContext.ViewData is an incompatibile type. + // ViewContext.ViewData is an incompatible type. if (context.ViewData == null) { // Create ViewDataDictionary(IModelMetadataProvider, ModelStateDictionary). diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionary.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionary.cs index 08d9f3bc0d..9a3a7b055e 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionary.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionary.cs @@ -33,14 +33,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures ModelStateDictionary modelState) : this(metadataProvider, modelState, declaredModelType: typeof(object)) { - if (metadataProvider == null) - { - throw new ArgumentNullException(nameof(metadataProvider)); - } - if (modelState == null) - { - throw new ArgumentNullException(nameof(modelState)); - } } /// @@ -56,10 +48,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures public ViewDataDictionary(ViewDataDictionary source) : this(source, source.Model, source._declaredModelType) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } } /// @@ -77,10 +65,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures public ViewDataDictionary(ViewDataDictionary source, object model) : this(source, model, declaredModelType: typeof(object)) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } } /// @@ -94,10 +78,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures internal ViewDataDictionary(IModelMetadataProvider metadataProvider) : this(metadataProvider, new ModelStateDictionary()) { - if (metadataProvider == null) - { - throw new ArgumentNullException(nameof(metadataProvider)); - } } /// @@ -119,14 +99,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures Type declaredModelType) : this(metadataProvider, new ModelStateDictionary(), declaredModelType) { - if (metadataProvider == null) - { - throw new ArgumentNullException(nameof(metadataProvider)); - } - if (declaredModelType == null) - { - throw new ArgumentNullException(nameof(declaredModelType)); - } } /// @@ -198,10 +170,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures protected ViewDataDictionary(ViewDataDictionary source, Type declaredModelType) : this(source, model: source.Model, declaredModelType: declaredModelType) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } } /// diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionaryOfT.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionaryOfT.cs index 7a4ff22f3f..447e6233fe 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionaryOfT.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewDataDictionaryOfT.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Microsoft.AspNetCore.Mvc.ViewFeatures @@ -15,20 +14,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures /// For use when creating a for a new top-level scope. /// /// - // References may not show up due to ActivatorUtilities use in RazorPageActivator. + // References may not show up due to Type.GetConstructor() use in RazorPageActivator. public ViewDataDictionary( IModelMetadataProvider metadataProvider, ModelStateDictionary modelState) : base(metadataProvider, modelState, declaredModelType: typeof(TModel)) { - if (metadataProvider == null) - { - throw new ArgumentNullException(nameof(metadataProvider)); - } - if (modelState == null) - { - throw new ArgumentNullException(nameof(modelState)); - } } /// @@ -48,14 +39,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures /// /// /// - // References may not show up due to ActivatorUtilities use in RazorPageActivator. + // References may not show up due to Type.GetConstructor() use in RazorPageActivator. public ViewDataDictionary(ViewDataDictionary source) : base(source, declaredModelType: typeof(TModel)) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } } /// @@ -80,10 +67,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures public ViewDataDictionary(ViewDataDictionary source, object model) : base(source, model, declaredModelType: typeof(TModel)) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } } /// @@ -94,10 +77,6 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures internal ViewDataDictionary(IModelMetadataProvider metadataProvider) : base(metadataProvider, declaredModelType: typeof(TModel)) { - if (metadataProvider == null) - { - throw new ArgumentNullException(nameof(metadataProvider)); - } } public new TModel Model diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewExecutor.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewExecutor.cs index 85fe08f8a7..4fe015770c 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/ViewExecutor.cs @@ -130,11 +130,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures throw new ArgumentNullException(nameof(view)); } - var services = actionContext.HttpContext.RequestServices; if (viewData == null) { + var services = actionContext.HttpContext.RequestServices; var metadataProvider = services.GetRequiredService(); - viewData = new ViewDataDictionary(metadataProvider); + viewData = new ViewDataDictionary(metadataProvider, actionContext.ModelState); } if (tempData == null)