How do I add an MVC controller to a WebApi project in Visual Studio 2013?

I am trying to understand the concept of one I've done the whole exercise here. It's simple.

Now trying to understand further, I created a new Asp.Net project and selected Web API template as follows. Therefore, we can see that the MVC and Web API checkboxes are selected.

New Web Api project template in VS 2013

If I observe the project AccountController is ApiController and so there is no account and folder management in the views folder as expected.

Account controller for web api

Now my question is how to add the Mvc account controller to the above project? I know very well that if I select MVC in the new project dialog, I can get it.

New MVC project template in VS 2013

What I want is to add an MVC account controller along with the views as shown in the previous web api project.

Account Controller for MVC

It should be very easy I think. So can someone please describe some steps? How, for example, which model and context do we need to select, add a sketch and then add controller dialogs?

Add Scaffold dialogAdd Controller dialog after Scaffold dialog

In other words, I want to understand by looking at a controller, say AccountController is Api or Mvc as I understand what the model class and the associated data context is.


source to share

1 answer

The large number of scafold templates that exist are very useful for running an application. Even you can create a new WepApplication project and add the Nuget package AspNet.Identity Sample , which has many possibilities.

However, for your project, I recommend that you start with the Empty Web Api project and then start adding only the materials you need. This way you get a better understanding of how your Wep Api works with AspNet Identity (account management, third party providers like Google or Facebook, ...).

This step by step tutorial (and the next series) will help you implement and understand the Web Api and AspNet Identity, starting with the Empty Web Api project.

Hope it helps.



All Articles