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

青春壹個敷衍的年華 提交于 2019-12-25 19:36:19

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/37990874/how-to-pass-viewbag-data-from-view-to-another-component-template-that-i-call-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!