diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewDataDictionary.cs b/src/Microsoft.AspNet.Mvc.Core/ViewDataDictionary.cs
index 6b940b6e94..eca162da51 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ViewDataDictionary.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ViewDataDictionary.cs
@@ -33,7 +33,8 @@ namespace Microsoft.AspNet.Mvc
}
///
- /// copy constructor for use when model type does not change.
+ /// copy constructor for use when model type does not change or caller will
+ /// immediately set the property.
///
public ViewDataDictionary([NotNull] ViewDataDictionary source)
: this(source, source.Model)
@@ -50,9 +51,15 @@ namespace Microsoft.AspNet.Mvc
new CopyOnWriteDictionary(source, StringComparer.OrdinalIgnoreCase),
new TemplateInfo(source.TemplateInfo))
{
- _modelMetadata = source.ModelMetadata;
- // If we're constructing a derived ViewDataDictionary (or any other value type),
- // SetModel will throw if we try to set it to null. We should not throw in that case.
+ // Avoid copying information about the object type. To do so when model==null would confuse the
+ // ViewDataDictionary.ModelMetadata getter.
+ if (source.ModelMetadata?.ModelType != typeof(object))
+ {
+ _modelMetadata = source.ModelMetadata;
+ }
+
+ // If we're constructing a derived ViewDataDictionary where TModel is a non-Nullable value type,
+ // SetModel will throw if we try to call it with null. We should not throw in that case.
if (model != null)
{
SetModel(model);