diff --git a/samples/MvcSample.Web/Components/TagCloud.cs b/samples/MvcSample.Web/Components/TagCloud.cs
index 874cd8fcce..a7b736d878 100644
--- a/samples/MvcSample.Web/Components/TagCloud.cs
+++ b/samples/MvcSample.Web/Components/TagCloud.cs
@@ -37,6 +37,7 @@ namespace MvcSample.Web.Components
private string[] GetTags(int count)
{
+ @ViewBag.Title = count.ToString() + " Tags:";
return Tags.Take(count).ToArray();
}
}
diff --git a/samples/MvcSample.Web/Views/Shared/Components/Tags/Default.cshtml b/samples/MvcSample.Web/Views/Shared/Components/Tags/Default.cshtml
index be64295b8c..702a80c0a4 100644
--- a/samples/MvcSample.Web/Views/Shared/Components/Tags/Default.cshtml
+++ b/samples/MvcSample.Web/Views/Shared/Components/Tags/Default.cshtml
@@ -1,6 +1,7 @@
@model string[]
-
+
+
@ViewBag.Title
@foreach (var tag in Model)
{
@tag
diff --git a/samples/MvcSample.Web/Views/Shared/MyView.cshtml b/samples/MvcSample.Web/Views/Shared/MyView.cshtml
index d7f1a43800..a2f485bec1 100644
--- a/samples/MvcSample.Web/Views/Shared/MyView.cshtml
+++ b/samples/MvcSample.Web/Views/Shared/MyView.cshtml
@@ -134,6 +134,7 @@
@await Component.InvokeAsync("Tags", 15)
+
'@ViewBag.Title' should match page heading (still)
diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs
index b8f9308adc..ff66afa04d 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewComponent.cs
@@ -7,6 +7,8 @@ namespace Microsoft.AspNet.Mvc
[ViewComponent]
public abstract class ViewComponent
{
+ private dynamic _viewBag;
+
public HttpContext Context
{
get { return ViewContext == null ? null : ViewContext.HttpContext; }
@@ -14,6 +16,19 @@ namespace Microsoft.AspNet.Mvc
public IViewComponentResultHelper Result { get; private set; }
+ public dynamic ViewBag
+ {
+ get
+ {
+ if (_viewBag == null)
+ {
+ _viewBag = new DynamicViewData(() => ViewData);
+ }
+
+ return _viewBag;
+ }
+ }
+
public ViewContext ViewContext { get; set; }
public ViewDataDictionary ViewData { get; set; }