asp.net mvc 4 - Access a viewbag property in reactjs -
i developing web application , using reactjs , mvc c#.
i want know if jsx included in cshtml , possible access viewbag property in jsx? have object or id passed jsx rendered in ui?
viewbag
rendered , execute in server side, react invoked on browser (client).
main options are:
- global variable - in razor (
.cshtml
) can set global objectwindow.param = viewbag.param
. , access react.
const x = window.param
pass value (primitives only) root element of react via
data-attribute
, grab before 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)
Comments
Post a Comment