admin管理员组文章数量:1422077
i am developing a web application , where i am using reactjs and MVC c#.
I would want to know if jsx is included in a cshtml , is it possible to access a viewbag property in jsx? i would have a object or id to be passed to jsx which will be rendered in the UI?
i am developing a web application , where i am using reactjs and MVC c#.
I would want to know if jsx is included in a cshtml , is it possible to access a viewbag property in jsx? i would have a object or id to be passed to jsx which will be rendered in the UI?
Share Improve this question edited Apr 28, 2019 at 6:37 Sagiv b.g 31k10 gold badges72 silver badges104 bronze badges asked Sep 14, 2017 at 6:48 MaddyMaddy 1051 silver badge11 bronze badges1 Answer
Reset to default 7ViewBag
is rendered and execute in the server side, react is invoked on the browser (client).
Your main options are:
- Global variable - In the razor (
.cshtml
) you can set a global objectwindow.param = ViewBag.param
. and access it from react.
const x = window.param
Pass a value (primitives only) to the root element of react via a
data-attribute
and grab it before you call render: example:// razor (.cshtml) <div id="root" data-param="@ViewBag.param"></div> // react const root = document.getElementById('root'); const param = root.getAttribute('data-param'); render(<App myParam={param}/>, root)
本文标签: javascriptAccess a viewbag property in reactjsStack Overflow
版权声明:本文标题:javascript - Access a viewbag property in reactjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745328682a2653709.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论