21

I know that Asp.Net MVC and Asp.Net Web API were merged into one code in Asp.net Core and they inherit from Controller base class and can all return implementations of IActionResult. it be a View for MVC or Json for web api.

But when i want to create a Asp.net Core project, it offers two templates (Web Application and Web Api ), according to what i said in above, there is no differences between these controllers, why there is two templates? is there any differences that i don't know about it?

2 Answers 2

18

The difference between 2 templates is-

The WebAPI template starts with a Controller class that will allow you to respond to RESTful requests at the /api/Values endpoint.

The Web Application template will give you an MVC framework enabled project with some Razor views, the bootstrap CSS framework and jQuery library installed.

If you want to create project with both MVC and API controllers then I would suggest to go with ASP.NET Core Web Application template and add require dependencies.

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

Comments

16

The web application template will create folders and import stuff needed for a web application such as jquery, css etc. Web api template will create folders and import stuff for a web api. Also the controllers created by default will have different implementations, for example, web application will be returning views and the views will be created in the appropriate folder.

So although they derive from the same controllers, each type of project requires different dependencies.

If I were you I would go ahead and create one for each type and see the difference.

If you want to have both web api and web application in the same project, use areas. This way your web and api will have separate controllers, folders and models. Also if you want to separate them in the future, it will be easy to do so.

4 Comments

I want to build a project which have two api and controllers, its better that i seperate them from each other and create them in different projects or in the same project(in controller folder i have both MVC an Api controller)?
Is there any advantage (or disadvantage) to creating a blank solution and then just adding an asp.net core web app project and an asp.net core web api project vs just a separate folder or area for the api project within the web application project?
I know this is old, but ya'll explained the difference between the 2, but didn't explain the reasons for deciding between the 2 (other than just "wanting an api app" or "not wanting an api app / wanting an mvc app).
@RobertoRaymon The question is not about deciding between the 2 but what the difference is. In any case, if you want an application with screens, forms etc. then you want the MVC template. If you want just an API, then the Web API template.

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.