Reputation: 1
I want to learn React.js, but most of the tutorials show how to integrate ASP.NET Core Web APIs with React.js, while I did not find any tutorial for using React.js with ASP.NET Core MVC. Any advice? Can I assume that React.js works only with ASP.NET Core Web APIs, where React.js is used to consume the JSON returned from the API?
Upvotes: 6
Views: 8716
Reputation: 21656
I want to learn React.js, but most of the tutorials show how to integrate ASP.NET Core Web APIs with React.js, while I did not find any tutorial for using React.js with ASP.NET Core MVC. Any advice? Can I assume that React.js works only with ASP.NET Core Web APIs, where React.js is used to consume the JSON returned from the API?
No, the react.js could work with Asp.net core web API and the Asp.net core MVC. In this scenario, the react.js act as the Front-End, and the API and MVC controller will act as the backend.
To answer the question more clearly, we need to understand the concept of front-end and back-end separation. As we all know, in the MVC pattern, it can be divided into data layer, logic layer and view layer. This view layer is what we call the front-end, which is mapped to the code level, namely, HTML, JS, CSS and other code files. The data layer and logic layer are more back-end parts. These files will be in a project and will not be developed, tested and deployed separately.
For the Front-End separation application, front-end and back-end are separated in different projects. The front-end has special front-end developers to develop and test, while the back-end has back-end developers to develop and test. They interact with each other through API.
So, to create the Front-End separation application, most developers will choose to create a React.js(Angular.js or Vue.js) application as the front-end application (because the React is a JavaScript library for building user interfaces) and use Asp.net core project as a back-end.
To use the React.js with Asp.net Core MVC application, you could use the React project template create a Asp.net core application (choose the react template when create Asp.net Core application via visual studio), then, in the React page, you could call the MVC controller to get data (it is similar with the API), after that render the data. Like this:
Upvotes: 11
Reputation: 2019
We use Web Api with angular framework or react so that we can bind data coming from the database with the angular or react controls in easy way by just calling HTTP services.
If you are planning to use normal mvc web application, you can do that, but real question is how will you transfer data coming from database in your mvc controller to angular or react components
Upvotes: 0