加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – 如何在ASP.NET MVC中使用React

发布时间:2020-12-15 21:00:02 所属栏目:asp.Net 来源:网络整理
导读:我想试用React并开始学习 here教程 使用Internet模板,在_Layout.cshtml中添加了所需的脚本引用,并将以下脚本放在About.cshtml中. 带有’@’字符的代码给出了麻烦: script type="text/jsx" /** * @jsx React.DOM */ // The above declaration must remain in
我想试用React并开始学习 here教程
使用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说:

The name ‘jsx’ does not exist in the current context

请提供一些指示

问候.

解决方法

我刚刚发布了 ReactJS.NET,它可以让你轻松地将JSX编译为JavaScript.使用ReactJS.NET,您可以将代码放入.jsx文件(例如/Scripts/HelloWorld.jsx),然后通过脚本标记引用它:
<script src="@Url.Content("~/Scripts/HelloWorld.jsx")"></script>

此外,还支持ASP.NET Bundling和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组件的可选服务器端呈现.敬请关注!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读