与MVC互动,简单的应用程序,出现错误

时间:2018-07-16 02:29:43

标签: asp.net-mvc reactjs

我正在VS 2015中使用文档here创建一个测试React Web应用程序,但出现错误

  

未捕获到的SyntaxError:意外令牌<< / p>

我的代码

class CommentBox extends React.Component {
render() {
return (
  <div className="commentBox">
      Hello, world! I am a CommentBox.
  </div>
);
}
}

ReactDOM.render(
<CommentBox />,
document.getElementById('content')
);

enter image description here

enter image description here

我已安装的nuget软件包

enter image description here

1 个答案:

答案 0 :(得分:1)

在图像中,软件包列表用于服务器端渲染。您正在尝试渲染为客户端。

React.Web.MVC4 NuGet软件包用于服务器端。 例如:

class CommentBox extends React.Component {
      render() {
         return (
            <div className="commentBox">
                Hello, {this.props.name}! I am a CommentBox.
            </div>
        );
    }
} /* Script/App.js */


@using React.Web.mvc

@Html.React("CommentBox",new{
    name="John"
})  /* Index.cshtml */


namespace MyApp
{
    public static class ReactConfig
    {
        public static void Configure()
        {
            ReactSiteConfiguration.Configuration = new ReactSiteConfiguration()
                .AddScript("~/script/App.js");
        }
    }
}  /* AppStart/reactConfig.cs */

react.js with mvc server side