Search code examples
c#asp.net-mvcrazormodel-view-controllerviewbag

how to pass viewbag data from view to another component template that I call in this view


I have a ViewBag data from the controller that I get in the View. However, my view is made of multiple components and a component (Which is a html template and relevant JavaScript), has a placeholder for this data where I need to display this data.

How would I pass this @ViewBag.Data to the placeholder in another view (Template here). ?

Or, would it be easy to consider passing the data from Controller to another view?

Please help me with a sample snippet


Solution

  • If I understood correctly you can do this by using the same controller for your second view, like writing ng-controller="SameController" or creating an angular service or factory and sharing your data between two different controllers that each one serves a specific template/view.