I\'m trying to setup a new project in Visual Studio that is going to be MVC 5 with a single page app written in ReactJS. So I followed the guide on the ReactJS website.
The first thing you need to ensure is that you are indeed creating an ASP.NET MVC 5 application and not an ASP.NET Core, as the tutorials are different.
For ASP.NET MVC 4 & 5: https://reactjs.net/getting-started/tutorial_aspnet4.html For ASP.Net Core: https://reactjs.net/getting-started/tutorial.html
If you are creating an ASP.NET MVC 5 application then follow the steps below:
Steps:
Install-Package react.js
Install-Package React.Web.Mvc4
You will notice that a folder called 'react' will be created in 'Scripts'
Tutorial.jsx
This is your where your react code will go.
var CommentBox = React.createClass({
render: function() {
return (
Hello, world! I am a CommentBox.
);
}
});
ReactDOM.render(
,
document.getElementById('content')
);
Index view, which is in the Home folder under views, place the following code:@{ Layout = null; }
Hello React
Now if you run the application you should get the following in your browser window: 'Hello, world! I am a CommentBox.'