1

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?

4
  • Can you add the web api project to your MVC solution?CommentedJul 8, 2021 at 8:32
  • I added it via Add Reference.CommentedJul 8, 2021 at 8:34
  • 1
    You can simply add another MVC project on your solution, then try to call Web API from MVC project like a client side project. Feel free to let me know if you require further asistance.CommentedJul 8, 2021 at 9:46
  • I added MVC project to my solution and I will use HTTP Client to reach my api methods. But how can I run or debtug multiple projects(api and mvc) on vscode?CommentedJul 8, 2021 at 12:12

1 Answer 1

4
  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 hereenter 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).

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.