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:

  1. global variable - in razor (.cshtml) can set global object window.param = viewbag.param. , access react.
    const x = window.param
  2. 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

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -