diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs index cc6124201e..3dc5a53e13 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/HtmlHelperOfT.cs @@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Mvc.Rendering { var metadata = ExpressionMetadataProvider.FromLambdaExpression( expression, - new ViewDataDictionary(MetadataProvider), + new ViewDataDictionary(ViewData, model: null), MetadataProvider); var expressionText = ExpressionHelper.GetExpressionText(expression); diff --git a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/TemplateBuilder.cs b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/TemplateBuilder.cs index f354bf9127..418a02bb92 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/TemplateBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Rendering/Html/TemplateBuilder.cs @@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Mvc.Rendering return string.Empty; } - var viewData = new ViewDataDictionary(_viewData) + var viewData = new ViewDataDictionary(_viewData, model: null) { Model = _metadata.Model, ModelMetadata = _metadata diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentActivator.cs b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentActivator.cs index 67e8c9f728..873dfb1c3d 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentActivator.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentActivator.cs @@ -57,10 +57,7 @@ namespace Microsoft.AspNet.Mvc typeof(ViewDataDictionary), (context) => { - return new ViewDataDictionary(context.ViewData) - { - Model = null - }; + return new ViewDataDictionary(context.ViewData); } } }; diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs index 5ae35e94ab..01cdbabeb5 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs @@ -65,12 +65,7 @@ namespace Microsoft.AspNet.Mvc public ViewViewComponentResult View(string viewName, TModel model) { - var viewData = new ViewDataDictionary(ViewData); - if (model != null) - { - viewData.Model = model; - } - + var viewData = new ViewDataDictionary(ViewData, model); return new ViewViewComponentResult(ViewEngine, viewName, viewData); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewDataDictionaryOfT.cs b/src/Microsoft.AspNet.Mvc.Core/ViewDataDictionaryOfT.cs index 8df9997a18..a4c063f3dd 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ViewDataDictionaryOfT.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ViewDataDictionaryOfT.cs @@ -7,12 +7,6 @@ namespace Microsoft.AspNet.Mvc { public class ViewDataDictionary : ViewDataDictionary { - /// - public ViewDataDictionary([NotNull] IModelMetadataProvider metadataProvider) - : base(metadataProvider, declaredModelType: typeof(TModel)) - { - } - // References may not show up due to ITypeActivator use in RazorPageActivator. /// /// Initializes a new instance of the class. @@ -75,6 +69,16 @@ namespace Microsoft.AspNet.Mvc { } + /// + /// Initializes a new instance of the class. + /// + /// Internal for testing. + /// + internal ViewDataDictionary([NotNull] IModelMetadataProvider metadataProvider) + : base(metadataProvider, declaredModelType: typeof(TModel)) + { + } + public new TModel Model { get diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorPageActivator.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorPageActivator.cs index 74dd98d87f..aa4f99dd48 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorPageActivator.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorPageActivator.cs @@ -47,13 +47,14 @@ namespace Microsoft.AspNet.Mvc.Razor // ViewContext.ViewData is an incompatibile type. if (context.ViewData == null) { - // Create ViewDataDictionary(metadataProvider); + // Create ViewDataDictionary(IModelMetadataProvider, ModelStateDictionary). return (ViewDataDictionary)_typeActivator.CreateInstance(context.HttpContext.RequestServices, - activationInfo.ViewDataDictionaryType); + activationInfo.ViewDataDictionaryType, + context.ModelState); } else if (context.ViewData.GetType() != activationInfo.ViewDataDictionaryType) { - // Create ViewDataDictionary(ViewDataDictionary); + // Create ViewDataDictionary(ViewDataDictionary). return (ViewDataDictionary)_typeActivator.CreateInstance(context.HttpContext.RequestServices, activationInfo.ViewDataDictionaryType, context.ViewData);