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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745328682a4622775.html
评论列表(0条)