0

I have two isolated applications one as a Web API using .Net core 3.1 and another one for Client-side using React and the two apps contact each other by HTTP requests now the challenge is I wanna integrate both of them as MVC so what is the recommended steps to do the integration.

1 Answer 1

1

If you'd like to migrate your existing WebAPI backend and React frontend apps to ASP.NET Core MVC, you may need to implement these functionalities from scratch in your new ASP.NET Core MVC project.

You can check each React component and the data passed/handled in that component, then create corresponding controller action and view page to implement same in MVC.

Note: normally WebAPI backend response and return data to React frontend, then we handle data on frontend and render it to expected html. In MVC, controller action usually return view result and pass view model data to view for rendering the web page.

For more information about "Passing data to views", please check this doc:

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/overview?view=aspnetcore-5.0#passing-data-to-views

Besides, partial view and view component in ASP.NET Core enables us to implement a reusable and modular unit, we can implement reusable rendering logic as partial view or view component, then invoke it in other view.

For details about partial view and view component, please check these docs:

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-5.0

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-components?view=aspnetcore-5.0

Sign up to request clarification or add additional context in comments.

4 Comments

but that I mean I need to rebuild the React Component and pages or convert them from React to .cstml pages?
If you'd like to migrate existing WebAPI (backend) + React (frontend) apps to ASP.NET Core MVC, you do need to rebuild them in controller with view(s). But if you just want to create a new MVC project that would consume same backend service (WebAPI) and expose some endpoint(s) for React frontend consuming, you do not need to convert your React app.
the second option that you mentioned is something like this dotnetcorecommunity.blogspot.com/2020/02/… , Right ?
If you'd like to add and use React component with ASP.NET Core MVC, some NuGet packages such as React.AspNet etc that mentioned in above blog you shared would help achieve the requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.