Dogan Cignakli
Dogan Cignakli

Reputation: 87

Adding Asp Net Core Web API Project to MVC Project

I created a solution with 4 layers which its names; Api,Entities,DataAccess and Services. Now I want to add MVC project to my solution to see my datas simple web interface.(I am planning learn Html and Razor).

Api layer is ASPNet Core WebAPI project(with api controllers and CRUD processes) and the others are .Net classlibs. How can I add MVC project for views and how can I use my api from this MVC project?

Upvotes: 1

Views: 810

Answers (1)

Chinmay T
Chinmay T

Reputation: 1133

  1. Right Click on the solution in VS2019 and add project > Add Asp.net core web app. Select the right framework version, authorization if you want to use it later on.

  2. To run multiple projects to gather on VS2019.

Right-click Solution > Set Startup Projects > Choose multiple projects > Choose your API and MVC project as the start.

Make Sure the API project is on top to start it first before the MVC project. enter image description here enter image description here

  1. In the MVC project you need to consume your API endpoints, by adding HttpClient or HttpClientFactory ( I recommend HttpClientFactory, google its advantages).

Upvotes: 4

Related Questions