Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

ViewBag doesn't propagate back to parent #861

Closed
victorhurdugaci opened this issue Jul 24, 2014 · 3 comments
Closed

ViewBag doesn't propagate back to parent #861

victorhurdugaci opened this issue Jul 24, 2014 · 3 comments
Labels

Comments

@victorhurdugaci
Copy link
Contributor

Run MusicStore and look at the title of the page. Notice that the property coming from the ViewBag is empty and the title is " - Music store"

cc @pranavkm - for code
cc @Praburaj - this could be checked as part of the automation

This is blocking the sample I'm working on

pranavkm added a commit that referenced this issue Jul 25, 2014
For pages that can pop back (e.g. Partial pages \ View Components), the
invoking component already creates a new ViewContext. ViewStart, Pages
and Layouts need to share the same Layout. This is required for sharing
ViewData values (such as title).

Fixes #861
pranavkm added a commit that referenced this issue Jul 25, 2014
For pages that can pop back (e.g. Partial pages \ View Components), the
invoking component already creates a new ViewContext. ViewStart, Pages
and Layouts need to share the same Layout. This is required for sharing
ViewData values (such as title).

Fixes #861
@Praburaj
Copy link
Contributor

@victorhurdugaci - I'll add a check for this in the automation.

@VaclavElias
Copy link

HI @victorhurdugaci, @Praburaj was this issue resolved?

When I set ViewBag.Title in the Controller I can see it in my ViewComponent View and Layout meta.

  1. I can override it in the ViewComponent class and see in my ViewComponent View but the Layout meta displays the one defined in the Controller.

  2. I can override it in ViewComponent View and see in my ViewComponent View but the Layout meta displays the one defined in the Controller.

Shouldn't it propagate also to Layout from ViewComponent class or ViewComponent View?

If this is intended for ViewComponent what is the way around as I need to display my Title and Description In Layout which get defined in ViewComponent class.

Update: I am using Beta7.

This is how I call my ViewComponent

@await Component.InvokeAsync("StaticPage", Model)

When I debug it, just outside this all ViewBags defined in ViewComponent became null.
Thank you.

@VaclavElias
Copy link

I think I have never been aware that Partials and ViewComponents have got its own ViewBags and found a way around from your collagues :) #3143

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants