Asp.net-Mvc-4
如何在 ASP.NET MVC 中使用 React
我想試用 React 並開始按照這裡的教程 使用 Internet 模板,在 _Layout.cshtml 中添加所需的腳本引用,並將以下腳本放在 About.cshtml 中。
帶有“@”字元的這段程式碼很麻煩:
<script type="text/jsx"> /** * @jsx React.DOM */ // The above declaration must remain intact at the top of the script. // Your code here </script>MVC 說:
目前上下文中不存在名稱“jsx”
請提供一些指點
問候。
我剛剛發布了ReactJS.NET,它可以讓你輕鬆地將 JSX 編譯為 JavaScript。使用 ReactJS.NET,您可以將程式碼放入 .jsx 文件(例如
/Scripts/HelloWorld.jsx),然後通過腳本標籤引用它:<script src="@Url.Content("~/Scripts/HelloWorld.jsx")"></script>此外,ASP.NET Bundling and Minification和Cassette都受支持。
原始答案(2014 年 4 月 4 日之前):
你需要
@通過寫兩次來逃避:<script type="text/jsx"> /** * @@jsx React.DOM */ // The above declaration must remain intact at the top of the script. // Your code here </script>我目前正在做一些事情,以使從 ASP.NET 中使用 React 變得更容易,這應該很快就會出來。這包括 JSX 的伺服器端編譯(動態和通過 ASP.NET 縮小和組合)和可選的 React 組件的伺服器端渲染。敬請關注!