Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Mvc/Mvc.TagHelpers/src/PartialTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class PartialTagHelper : TagHelper

private readonly ICompositeViewEngine _viewEngine;
private readonly IViewBufferScope _viewBufferScope;
private ViewDataDictionary _viewData;

/// <summary>
/// Creates a new <see cref="PartialTagHelper"/>.
Expand Down Expand Up @@ -91,7 +92,19 @@ public object Model
/// <summary>
/// A <see cref="ViewDataDictionary"/> to pass into the partial view.
/// </summary>
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;
}

/// <summary>
/// Gets the <see cref="Rendering.ViewContext"/> of the executing view.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@page

@{
ViewData["Title"] = "PartialWithViewData";
}

<div>
<partial name="_PrintViewData" view-data-id="123" view-data-returnUrl='"/dashboard"' />
</div>

<div>
<partial name="_PrintViewData" view-data-id="456" view-data-name='"John Doe"' />
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h4>ViewData Values</h4>
<dl>
@foreach (var key in ViewData.Keys)
{
<dt>@key</dt>
<dd>@ViewData[key]</dd>
}
</dl>