diff --git a/src/Mvc/Mvc.TagHelpers/src/PartialTagHelper.cs b/src/Mvc/Mvc.TagHelpers/src/PartialTagHelper.cs index 890a92d6c2ec..4bd2adcfe6fd 100644 --- a/src/Mvc/Mvc.TagHelpers/src/PartialTagHelper.cs +++ b/src/Mvc/Mvc.TagHelpers/src/PartialTagHelper.cs @@ -28,6 +28,7 @@ public class PartialTagHelper : TagHelper private readonly ICompositeViewEngine _viewEngine; private readonly IViewBufferScope _viewBufferScope; + private ViewDataDictionary _viewData; /// /// Creates a new . @@ -91,7 +92,19 @@ public object Model /// /// A to pass into the partial view. /// - public ViewDataDictionary ViewData { get; set; } + [HtmlAttributeName("view-data", DictionaryAttributePrefix = "view-data-")] + public ViewDataDictionary ViewData + { + get + { + if (_viewData == null) + { + _viewData = new ViewDataDictionary(ViewContext.ViewData); + } + return _viewData; + } + set => _viewData = value; + } /// /// Gets the of the executing view. diff --git a/src/Mvc/test/WebSites/HtmlGenerationWebSite/Areas/Customer/Pages/PartialWithViewData.cshtml b/src/Mvc/test/WebSites/HtmlGenerationWebSite/Areas/Customer/Pages/PartialWithViewData.cshtml new file mode 100644 index 000000000000..39e59596fc8f --- /dev/null +++ b/src/Mvc/test/WebSites/HtmlGenerationWebSite/Areas/Customer/Pages/PartialWithViewData.cshtml @@ -0,0 +1,13 @@ +@page + +@{ + ViewData["Title"] = "PartialWithViewData"; +} + +
+ +
+ +
+ +
\ No newline at end of file diff --git a/src/Mvc/test/WebSites/HtmlGenerationWebSite/Areas/Customer/Pages/_PrintViewData.cshtml b/src/Mvc/test/WebSites/HtmlGenerationWebSite/Areas/Customer/Pages/_PrintViewData.cshtml new file mode 100644 index 000000000000..78c371726585 --- /dev/null +++ b/src/Mvc/test/WebSites/HtmlGenerationWebSite/Areas/Customer/Pages/_PrintViewData.cshtml @@ -0,0 +1,8 @@ +

ViewData Values

+
+ @foreach (var key in ViewData.Keys) + { +
@key
+
@ViewData[key]
+ } +
\ No newline at end of file